Numpy and SciPy are packages for numerical computation and scientific computing, for Python.
One wrinkle with NumPy/SciPy that needs to be ironed out is the difficulty of installation on certain OSes, and particularly, architectures.The SciPy SuperPack has done a good job of taking care of this issue, but it has not yet been updated for 2.7.1 and manually hacking away at its script has not worked for me.
I cannot take credit for the instructions in this article. A brave warrior, Jeremy Conlin, somehow managed to figure out how to install 64-bit NumPy and SciPy, with 64-bit Python 2.7.1 on Snow Leopard; he posted the directions to the SciPy User mailing list on February 24. I followed the directions, and miraculously they worked. I am reproducing them here for Google bait.
Install Python 2.7.1
1. Download the universal Mac 2.7.1 installer here (Python 2.7.1 Mac OS X 64-bit/32-bit x86-64/i386 Installer). Typically, Python will be installed to /Library/Frameworks/Python.framework/Versions/2.7/, but may be in other locations.
2. Verify that your new version of Python is 64-bit enabled. Note: Python installations typically do not get toggled as the default Python, so find the location of the 2.7.1 Python executable. On my machine, it is /Library/Frameworks/Python.framework/Versions/2.7/bin/python. python2.7 should also work.
Load Python 2.7.1 and execute the code below. If you get 64, then you are ready to proceed.
import sys from math import log log(sys.maxsize, 2) + 1
Another way is to execute the following. If you get 1099511627776 (and NOT 1099511627776L) you are in good shape.
2**40
(This tip comes from Aaron Meurer’s SymPy blog)
Install gfortran
1. Download gfortran-4.2.3 here and double-click the file to mount the disk image.
2. Create a temporary directory (I call it tmp here) and run the following commands.
cd tmp mkdir gfortran cd gfortran pax -zrvf /Volumes/GNU\ Fortran\ 4.2.3/gfortran.pkg/Contents/Archive.pax.gz . cp -r usr/local/* /usr/local
Drop Down to the Root Shell
NOTE: From this point forward, I dropped to the root command prompt (sudo su -) so that I had full control over the environment. This is mainly due to the way to the shell deals with PYTHONPATH and the complications that can stem from it when installing with root privileges.
Locate the Python 2.7.1 distribution and find a directory that ends in site_packages. For example, for me this is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/.
Assuming Bash is your shell of choice, enter the following
export PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
Or, for tcsh,
setenv PYTHONPATH /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
Install distribute-0.6.14
The next few steps follow the typical Python package installation method. I use python2.7 rather than python just to make sure that my system is using 2.7.1 and not built in 2.6.1.
Distribute adds tools for installing Python modules including pip and easy_install.
curl -O http://pypi.python.org/packages/source/d/distribute/distribute-0.6.15.tar.gz tar -xzvf distribute-0.6.15.tar.gz cd distribute-0.6.15 python2.7 setup.py install
Install nose
Nose is al alternate test discovery and running process for unittest, similar to py.test.
Installation requires easy_install. I am not a fan of easy_install in the slightest. There are two important things to remember here:
On my system, easy_install for 2.7.1 is located at /Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install so I use:
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install nose
Install NumPy
Finally, we can install NumPy. Version 1.5.1 is the first version that apparently works with Python 3.
curl -O http://downloads.sourceforge.net/project/numpy/NumPy/1.5.1/numpy-1.5.1.tar.gz tar xzvf numpy-1.5.1.tar.gz cd numpy-1.5.1 sudo python2.7 setup.py install
Then, open Python and execute the following to import the library, and test it. On my system, all tests passed.
import numpy numpy.test()
Install SciPy
Next, install SciPy. Version 0.9 is the first version that is compatible with Python 3.
curl -O http://downloads.sourceforge.net/project/scipy/scipy/0.9.0/scipy-0.9.0.tar.gz tar xzvf scipy-0.9.0.tar.gz cd scipy-0.9.0 sudo python2.7 setup.py install
Then, open Python and execute the following to import the library, and test it. On my system, all but 14 tests passed.
import scipy scipy.test()
Install readline
readline provides functions for completion and reading/writing of history files from the Python interpreter (up/down arrow).
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install readline
Install IPython
IPython provides an enhanced command line interface to the Python interpreter. It is much more pleasant to work with than the standard command line interface.
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install ipython
Install wxPython
wxPython is a graphical user interface toolkit for Python. Up until recently, this was the blocker in the process — there was no 64-bit version of wxPython for Mac. Download the DMG here and double click the installer. Versions for Cocoa and Carbon are provided, but Python 2.7.1 apparently requires the Cocoa version.
Install matplotlib
matplotlib provides the plotting interface which is crucial to SciPy. Installing matplotlib is always the most complicated part of the process.
wget http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0.1/matplotlib-1.0.1.tar.gz tar xzvf matplotlib-1.0.1.tar.gz cd matplotlib-1.0.1
Then, open the file make.osx, find lines that look like below, and make the appropriate changes
PYVERSION=2.7 ZLIBVERSION=1.2.5 PNGVERSION=1.4.5 FREETYPEVERSION=2.4.4
Finally, delete line 63. Line 63 looks like:
cp .libs/libpng.a . &&\
Within the matplotlib-1.0.1 directory, download the following archives. Do not extract them!
Or execute the following commands within the matplotlib-1.0.1 directory.
wget http://zlib.net/zlib-1.2.5.tar.gz wget http://downloads.sourceforge.net/project/libpng/libpng14/older-releases/1.4.5/libpng-1.4.5.tar.gz wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.4.tar.bz2
Finally, install matplotlib-1.0.1 using the following command
PREFIX=$PYTHONROOT make -f make.osx deps mpl_install
where PYTHONROOT is the directory containing the pacakage tree. On my system, it is /Library/Frameworks/Python.framework/Versions/2.7/.
Finally, enter Python and test matplotlib.
import matplotlib.pyplot as pyplot pyplot.plot([1,2,3])
If installation was successful, a plot like the following should appear.
Hopefully this is helpful to someone, and here’s to hoping a SciPy Superpack for Python 2.7.1 will be released soon!