Monday, January 11, 2010

I've switched to iTerm

I was using GNU screen for a while. I liked having only one window open for multiple sessions in Mac OS X. However, setting up the configuration is not an easy feat. In recent months, however, I've switched to iTerm. I was against a tabbed command line environment because I didn't want to use the mouse to change tabs. But in iTerm you can cycle through the tabs with Command-arrow. You can get iTerm from their sourceforge page. I know that screen can do much more than iTerm, but I'm not really using those features, so for now iTerm will suffice.

Monday, January 4, 2010

Install numpy 2.6 on Snow Leopard (Mac OS X 10.6) from source

Here are the problems I was facing with using NumPy with Python 2.6.1 on Mac OS X 10.6.2 (Snow Leopard). This might be a bit convoluted, but bear with me.

First, in order to call STAF from a Python script, I built PYSTAF.so from source. However, the only way to get it to work is to run Python in 32-bit mode:

export VERSIONER_PYTHON_PREFER_32_BIT=yes

This then caused problems with NumPy:

Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg/numpy/__init__.py", line 130, in
import add_newdocs
File "/Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg/numpy/add_newdocs.py", line 9, in
from lib import add_newdoc
File "/Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg/numpy/lib/__init__.py", line 4, in
from type_check import *
File "/Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg/numpy/lib/type_check.py", line 8, in
File "/Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg/numpy/core/__init__.py", line 8, in
import numerictypes as nt
File "/Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg/numpy/core/numerictypes.py", line 737, in
_typestr[key] = empty((1,),key).dtype.str[1:]
ValueError: array is too big.

According to Numpy Ticket #1221 (http://projects.scipy.org/numpy/ticket/1221) this is fixed in revision 7793. However, I was trying to use r7542 as was installed by the SciPy SuperPack installer (http://macinscience.org/?page_id=6).

Still following along? Okay, so here's how I think I resolved my issues. I built and installed NumPy using the instructions on HyperJeff's blog: http://blog.hyperjeff.net/?p=160

First we need to move old versions of Numpy. In my case:

sudo mv /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy \
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy_APPLE_DEFAULT
sudo mv /Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg \
/Library/Python/2.6/site-packages/numpy-1.4.0.dev7542-py2.6-macosx-10.6-universal.egg-OLD

Then set the environment, build and install.

export MACOSX_DEPLOYMENT_TARGET=10.6
export CFLAGS="-arch i386 -arch x86_64"
export FFLAGS="-arch i386 -arch x86_64"
export LDFLAGS="-Wall -undefined dynamic_lookup -bundle -arch i386 -arch x86_64"
cd ~/tmp
svn co http://svn.scipy.org/svn/numpy/trunk numpy
cd numpy
python setup.py build --fcompiler=gnu95
sudo python setup.py install

If this doesn't work for you, you might want to run through all of the steps in HyperJeff's page above. I probably had much of the prerequisites from previously running the SciPy SuperPack installer.