W
hat follows is my collection of notes about installing a full 64-bit stack of NumPy, SciPy, PyLab, and all that entails on a fresh Snow Leopard system. If it helps out someone else trying to do something similar that would be great. If you look through what I've done and find things that could have been done better or in a more correct way, let me know. We will be building most things needed from source.
After trial and error, and plenty of the latter, I have streamlined the process down to installing the following, in order: gfortran, FFTW, UMFPACK, NumPy, SciPy and finally matplotlib (which includes PyLab).
Note: There used to be a great resource for this kinda thing, the Scipy Superpack page, but it appears now to be down, but hopefully not out. Until such a day, there is this page.
Please read the forums if you have any questions, disagree with something that I'm doing or just want to hear the fine things others have figured out. Those who have posted have important contributions and it's a great way to help others if you have some gem to contribute.
As of the last update of this article, I am using a clean installation of Snow Leopard, Mac OS X version 10.6.2, with developer tools installed, Xcode version 3.2.1.
I'm assuming MacPorts is not set up on your system yet, or at least I'm not making any use of it. If it is there, make sure your PATH environment variable doesn't have /opt/… listed before the other PATH directories or it may grab something from there when you don't want it to. (As with everything here, if you know better, by all means do what you know is best.) I use a tcsh environment, but the only difference here with my bash brethren will be in typing "export X=whatever" where I type "setenv X whatever".
Note: Things I didn't do… I'm sure there are lots of options that I should have turned on if I were savvy at all this stuff, but I did not include any instructions to build this stuff with Qt, VTK, or a lot of other neat stuff. So the fun interactive examples in matplotlib do not work with this. If someone wants to clue me in to the easiest way to make this happen, I'll be happy to add it to this tutorial. Also, some things like the wx libraries are disabled in this article, as they are still i386/ppc only in Snow Leopard, so if you want those you'll have to check into what that takes.
Also, a warning… While what is built below is indeed a full 32/64-bit stack, however, so far, 32-bit libraries will not work with it. For reasons that seem to be out of my hands, something isn't yet all dual-binary compatible and is only working in 64-bit mode. So if you need 32-bit compatibility, usually because of 32-bit modules you need to use, perhaps wait until a proper solution, here or elsewhere, is found.
The boxes below that show yellow text are meant to show what was is to be
typed by you. It does not show any of the crazy text that gets spit back out at you when you type it. Be sure to type in one line, let it do its thing, then type in the next.
Do not just copy and paste a multi-line block of these commands unless you know what you're doing.The boxes with light blue text are meant to show lines inside a text file that are to be edited by you at the appropriate time.
For this tutorial, I'm going to build everything in a fresh ~/tmp directory (I'll assume nothing else is in there too), so open up a fresh Terminal window, make it nice and wide, and, if it doesn't already exist, warm up your fingers with a simple command:
mkdir ~/tmp
This is the simplest step, merely downloading and installing the 4.2.3 version of gfortran listed on
this page of tools for use with R. While the gfortran binary itself is i386/ppc, it does create i386/x8664 binaries just fine.
Update: There is also a gfortran build 4.2 specifically for Snow Leopard under the "Alternative and experimental tools" section, if you'd rather use that. It's built against Snow Leopard's gcc 4.2 for Xcode 3.2, which in principle is a better match than the older 4.2.3 version. While it seems to work fine, as of this writing, gfortran-42-5646.pkg for Snow Leopard contains gfortran version 4.2.1, not 4.2.4 as labelled. Also, if you already installed another gfortran, this one is placed in /usr/bin, not /usr/local/bin, for some reason, so make sure that your $PATH is discovering the gfortran version you want to use before proceeding. (Quick check: see what "which gfortran" responds with at the Terminal after installing.)
As an aside, to have gfortran build a 64-bit binary, pass it the flag "-m64". To create a universal 32/64-bit binary, you can take an i386 and an x86
64 binary and create one universal with lipo: lipo -create bin32 bin64 -output binUniversal.
(On one machine I downloaded and installed gfortran 4.5.0 from source found on the GNU site, but for reasons I can't remember now, switched back to this one. I'm not sure if there's a reason to avoid the 4.5.0 version.)
I'm assuming /usr/local/bin is in everyone's path, but if you type echo $PATH and don't see it included, type this in (or the bash equivalent):
setenv PATH "${PATH}:/usr/local:/usr/local/bin"
This is just a straight-forward download and build, using the binary from the official FFTW site.
rehash
cd ~/tmp
curl -O http://www.fftw.org/fftw-3.2.2.tar.gz
tar xf fftw-3.2.2.tar.gz
cd fftw-3.2.2
./configure CC="gcc -arch i386 -arch x8664" CXX="g++ -arch i386 -arch x8664" CPP="gcc -E" CXXCPP="g++ -E"
make
sudo make install
How much fun would it be if everything were just as smooth as those two steps? UMFPACK requires being built along side AMD and UFconfig , where all 3 sources are located in the same parent directory. All of them are available on the U of Florida CISE site if you want to poke around there for other versions or whatnot.
cd ~/tmp
curl -O http://www.cise.ufl.edu/research/sparse/umfpack/current/UMFPACK.tar.gz
curl -O http://www.cise.ufl.edu/research/sparse/UFconfig/current/UFconfig.tar.gz
curl -O http://www.cise.ufl.edu/research/sparse/amd/current/AMD.tar.gz
tar xf AMD.tar.gz
tar xf UFconfig.tar.gz
tar xf UMFPACK.tar.gz
What follows comes from both the sparse docs in the projects and some helpful notes from Tony S Yu.
In your editor of choice, edit the file UFconfig/UFconfig.mk and make two changes. On line 51, change the F77 setting to read
F77 = gfortran
and then starting around line 295, un-comment the lines related to the Mac setup to look as follows:
#------------------------------------------------------------------------------
# Macintosh
#------------------------------------------------------------------------------
CC = gcc
CFLAGS = -O3 -fno-common -no-cpp-precomp -fexceptions -arch i386 -arch x8664
LIB = -lstdc++
BLAS = -framework Accelerate
LAPACK = -framework Accelerate
Now we copy some header files and then make the UMFPACK:
cp UFconfig/UFconfig.h AMD/Include/
cp UFconfig/UFconfig.h UMFPACK/Include/
cd UMFPACK
make
make hb
make clean
The make hb line is in just there to make sure it doesn't break, and the make clean is just to keep the place tidy.
Apple includes NumPy in a standard Snow Leopard install, and it's already 32/64-bit. Very nice and all, but it won't build against the SciPy source that I'll be using in the next step, so we need to build a fresh NumPy and to have it used instead of Apple's. We can tell Python to use our own by setting the search path appropriately.
For the next steps I set the environmental variables to build against 32 and 64bit architectures. If you open a new Terminal window or start a new shell for some reason in between these steps, be sure to reinstate these environmental variables:
setenv MACOSXDEPLOYMENTTARGET 10.6
setenv CFLAGS "-arch i386 -arch x8664"
setenv FFLAGS "-m32 -m64"
setenv LDFLAGS "-Wall -undefined dynamiclookup -bundle -arch i386 -arch x8664"
setenv PYTHONPATH "/Library/Python/2.6/site-packages/"
which, in bash-speak, is just
export MACOSXDEPLOYMENTTARGET=10.6
export CFLAGS="-arch i386 -arch x8664"
export FFLAGS="-m32 -m64"
export LDFLAGS="-Wall -undefined dynamiclookup -bundle -arch i386 -arch x8664"
export PYTHONPATH="/Library/Python/2.6/site-packages/"
Ok, now we're ready to build NumPy. First grab the source (which may take a bit), then build away. You can either build this from the source repository, which is more cutting-edge, but more prone to getting cut of course, or grab the current stable source (the .tar.gz, not the Mac-specific file!). I'll show what to do for both cases.
First the sane stable-source way. You have to use a web browser and go to the Numpy SourceForge Project page, download the latest stable source (I went with, v1.3.0), then mv the downloaded file to ~/tmp (at least that's what I'm assuming here). Future readers may have to adjust the following to suit their actual downloaded source versions. ("Hello, people of the future!")
cd ~/tmp
tar xf numpy-1.3.0.tar
cd numpy-1.3.0
Or, for those wishing to use the latest source, (which has the fun feature of following all current updates as they happen):
cd ~/tmp
svn co http://svn.scipy.org/svn/numpy/trunk numpy
cd numpy
To make NumPy aware of where we put our AMD and UMFPACK source files, copy the default site.cfg.example file
cp site.cfg.example site.cfg
and modify the contents of site.cfg, around line 99, to read like the following:
[amd]
librarydirs = /Users/jeff/tmp/AMD/Lib
includedirs = /Users/jeff/tmp/AMD/Include
amdlibs = amd
[umfpack]
librarydirs = /Users/jeff/tmp/UMFPACK/Lib
includedirs = /Users/jeff/tmp/UMFPACK/Include
umfpacklibs = umfpack
Obviously, change the /Users/jeff/tmp part to wherever you ended up putting those files.
Continuing, whichever way you went with the source,
python setup.py build --fcompiler=gnu95
sudo python setup.py install
Unable to find a more correct way to do the following, I have found that the system's NumPy gets in the way of building SciPy, so I change its name, to prevent it from making mischief. This is an ugly and fragile solution, but I'm unable to find a workable correct solution to this problem. After you're done with the whole install, feel free to change the library name back, but I'm not sure if it ends up interfering in daily use. (Please contribute if you know the proper way to handle this! See the many forum comments below for discussions about other ways to handle this.)
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/numpyX
Stable-source-style: Grab the latest stable source from the SciPy SourceForge Project, then…
cd ~/tmp
tar xf scipy-0.7.1.tar
cd scipy-0.7.1
python setup.py build
sudo python setup.py install
and source-repository-style:
cd ~/tmp
svn co http://svn.scipy.org/svn/scipy/trunk scipy
cd scipy
python setup.py build
sudo python setup.py install
Stable source, gotten from the matplotlib SourceForge page, and:
cd ~/tmp
tar xf matplotlib-0.99.1.1.tar
cd matplotlib-0.99.1.1
or grab the latest source:
cd ~/tmp
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib
cd matplotlib
and before we continue we need to first edit the file make.osx which is right in the directory you should be in now. Within the first few lines of the file you'll see something similar to what I have below, but not quite, so update it to include these changes:
MACOSXDEPLOYMENTTARGET=10.6
PREFIX=/usr/local
## You shouldn't need to configure past this point (and yet…)
PKGCONFIGPATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-arch i386 -arch x8664 -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX10.6.sdk"
LDFLAGS="-arch i386 -arch x8664 -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX10.6.sdk"
FFLAGS="-arch i386 -arch x8664"
and, since Snow Leopard's wx libraries are a touch behind the times and are compiled i386/ppc, edit line 57 (or thereabouts) of the file setup.cfg to comment out the following line:
wxagg = False
from here we can finally build matplotlib with the next, and final, two commands:
sudo make -f make.osx fetch deps mplbuild mplinstall
sudo python setup.py install
David, below, made the fine point of including the quick and easy steps to also pop iPython on your machine. You can check the download page to grab the latest source version, which for me was 0.10, and do as with the others above:
cd ~/tmp
curl -O http://ipython.scipy.org/dist/ipython-0.10.tar.gz
tar xf ipython-0.10.tar.gz
cd ipython-0.10
python setup.py build
sudo python setup.py install
and, voila, iPython, the more fun way to play with all of the above.
You may now want to rename the system's NumPy back to what it was, allowing it to be updated nicely when system updates come along, and hopefully it doesn't stir up any troubles:
sudo mv /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpyX \
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy
However, if you do run into troubles, rename it back to numpyX. On my system, re-enabling the system's NumPy causes trouble, but not everyone seems to need it set up this way. Sorry I can't be of more help on this issue (yet).
Ok, you're done. Scram. Beat it. Get to codin'. Well, if you want to actually see if it's working (and I really hope it is at this point), try running any number of different examples listed on the matplotlib examples page. Again, many of them do not work when they require libraries such as Qt or VTK, but most of them should work as advertised.
Hope this was of help to someone, if only myself in the future when installing it on other machines. Of course, by then, there'll be some great one-click install that'll do it for me, or just be totally built-in to the system the way NumPy already is (well, a boy can dream).