Instructions for Installing 64bit SciPy, Python 2.7.1 on MacOS X 10.6

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:

  1. PYTHONPATH must be set correctly, or easy_install will complain.
  2. If you have easy_install for another version of Python, make sure you use the version for 2.7.1 and not some previous version or easy_install will complain.

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!

  1. zlib 1.2.5
  2. libpng 1.4.5
  3. freetype 2.4.4

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!

17 comments to Instructions for Installing 64bit SciPy, Python 2.7.1 on MacOS X 10.6

  • Alain

    Unfortunately I wasted all afternoon yesterday trying to accomplish the same thing. It turns out that was bad timing, as your instructions proved to be very helpful. Thanks a lot for assembling them.

    • a

      It’s a pity you don’t have a donate button! I’d
      most certainly donate to this brilliant blog! I suppose for now
      i’ll settle for book-marking and adding your RSS feed to my Google account.

      I look forward to fresh updates and will share this website with my Facebook group.
      Chat soon!

  • Pep

    Very useful, indeed. Thank you very much!

  • Sam

    Awesome. Thank you so, so much. I’ve been trying to get this installed for so long.

    Mac Pro
    OS 10.6.6
    ActivePython 2.7.1.4 (ActiveState Software Inc.) based on
    Python 2.7.1 (r271:86832, Feb 7 2011, 11:33:10)
    [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
    64-bit enabled

    Some of the curl commands did not work, so I had to grab them manually.

    Also, as you pointed out, there is great danger in the different python installations competing. For some reason, even though I set the paths, the matplotlib installer was still trying to use the built-in 2.7 – and not the ActiveState version – where I had installed all the other dependencies. My solution was to blast the symbolic link from /opt/local/bin, which worked fine.

    Thanks again.

  • Andrew

    Thank you for the pointer. Been trying to make this work for a looong time.

    • Scott

      Thanks for writing this up! It worked great, up until the last command:

      PREFIX=/Library/Frameworks/Python.framework/Versions/2.7/ make -f make.osx deps mpl_install

      …which produced this error:

      Traceback (most recent call last):
      File “setup.py”, line 162, in
      if check_for_tk() or (options[‘build_tkagg’] is True):
      File “/Users/sbrinker/tmp/matplotlib-1.0.1/setupext.py”, line 832, in check_for_tk
      (Tkinter.__version__.split()[-2], Tkinter.TkVersion, Tkinter.TclVersion))
      IndexError: list index out of range
      make: *** [mpl_install] Error 1

      Don’t suppose you have any ideas on what might be wrong? Thanks!

  • Francesca

    Thank you for saving me many hours!

  • jkmacc

    Woohoo! Seriously, you rock.

  • Joshua Rogers

    Thanks so much for the tutorial – i’ve been needing to install scipy and pylab on my mbp for uni for a few days now and only just stumbled across your tut – it’s served me great πŸ˜€

  • Tim Buchheim

    Awesome. Thanks for sharing this with everyone! πŸ™‚

  • Michael Albrow

    Thanks for the tutorial. I followed the instructions but got a failure during the scipy install as follows:

    swig -python -o build/src.macosx-10.6-intel-2.7/scipy/sparse/linalg/dsolve/umfpack/_umfpack_wrap.c -outdir build/src.macosx-10.6-intel-2.7/scipy/sparse/linalg/dsolve/umfpack scipy/sparse/linalg/dsolve/umfpack/umfpack.i
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:192: Error: Unable to find ‘umfpack.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:193: Error: Unable to find ‘umfpack_solve.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:194: Error: Unable to find ‘umfpack_defaults.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:195: Error: Unable to find ‘umfpack_triplet_to_col.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:196: Error: Unable to find ‘umfpack_col_to_triplet.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:197: Error: Unable to find ‘umfpack_transpose.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:198: Error: Unable to find ‘umfpack_scale.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:200: Error: Unable to find ‘umfpack_report_symbolic.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:201: Error: Unable to find ‘umfpack_report_numeric.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:202: Error: Unable to find ‘umfpack_report_info.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:203: Error: Unable to find ‘umfpack_report_control.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:215: Error: Unable to find ‘umfpack_symbolic.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:216: Error: Unable to find ‘umfpack_numeric.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:225: Error: Unable to find ‘umfpack_free_symbolic.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:226: Error: Unable to find ‘umfpack_free_numeric.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:248: Error: Unable to find ‘umfpack_get_lunz.h’
    scipy/sparse/linalg/dsolve/umfpack/umfpack.i:272: Error: Unable to find ‘umfpack_get_numeric.h’
    error: command ‘swig’ failed with exit status 1

    Does anyone know how to fix this?
    (I’m running 10.6.7)

    • Ugh. I’ve never seen this before. It looks like a dependency that comes with SciPy is not being built correctly.

      There is some information at the link below, but not sure how helpful it is. It seems like a common problem on Mac, and might be related to Cholesky decomposition code:
      http://blog.hyperjeff.net/?p=160

  • Johan

    Thanks for the guide, the only problem I ran into was that Matplotlib had problem finding Tkinter but I manually applied this patch:
    https://github.com/matplotlib/matplotlib/commit/e4a34df93f6

    • Thanks for this info! I think it might help one of the other commenters! Sorry for taking so long to approve, I usually get an email when I have a comment to approve

  • Thanks Johan and Ryan. Installing matplotlib et al was a frustrating process, but this page was a huge help.

  • Rachel

    Thank you so much!! Worked like a charm!!

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>