Friday, November 19, 2010

Building Python again on OS X

I ran into a problem with RPy, and it was suggested that I build Python with debug enabled to troubleshoot. This is my record of the process. The folder holding the source for the release I wanted (2.6.6) is here, the download link is here. I did it with the browser and put the file on my Desktop and before doing anything else:

md5 ~/Desktop/Python-2.6.6.tgz
MD5 (Python-2.6.6.tgz) = b2f209df270a33315e62c1ffac1937f0

which matches the published value. Next: unpack and move to ~/Software, build with debug flag:

cd ~/Software/Python-2.6.4
./configure --prefix=/dev/null --with-pydebug --without-toolbox-glue
configure: WARNING: unrecognized options: --without-toolbox-glue
..

That option did not give a warning when building 2.6.4. Build for two cores with:

make -s -j2


./python.exe
Python 2.6.6 (r266:84292, Nov 19 2010, 09:54:35)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.



Getting RPy



easy_install instructions seem kind of complicated for a non-standard directory! (An oxymoron, to be sure). I tried just grabbing it from Source Forge, but couldn't make it work. Instead, I put this in ~/.pydistutils.cfg:

[install]
install_lib = ~/Library/Python/$py_version_short/site-packages
install_scripts = ~/bin

Then do:

easy_install rpy2

error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 2] No such file or directory: '/Users/telliott_admin/Library/Python/2.6/site-packages/test-easy-install-19210.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/Users/telliott_admin/Library/Python/2.6/site-packages/

This directory does not currently exist. Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).


ls /Users/telliott_admin/Library/Python
2.x

Well, OK

mkdir  /Users/telliott_admin/Library/Python/2.6/site-packages
easy_install rpy2

and.. it installs into 2.x! Launch Python

cd ~/Software/Python-2.6.6
./python.exe

p = '/Users/telliott_admin/Library/Python/2.x/site-packages/lib/python'
import sys
sys.path.insert(0,p)
sys.path

or do this before launch:

export PYTHONPATH=/Users/telliott_admin/Library/Python/2.x/site-packages/lib/python:$PYTHONPATH
cd ~/Software/Python-2.6.6
./python.exe


>>> from rpy2 import robjects
>>> robjects.r['pi'][0]
robjects.r['pi']

[52505 refs]
>>>

It works!

No comments: