Installing numpy+scipy on OS X Lion

2011-07-24

After a fresh upgrade of my Macbook Air with OS X Lion, I'm left with the default system Python, but nothing of my old stuff in the System Library path.

First attempt

I first tried to install numpy. The default installed version is 1.5.0, I want the latest version. This was quite simple

$ sudo easy_install numpy
$ python
>>> import numpy
>>> print numpy.__version__
1.6.1

Other easy install: scikits.learn (no dependency, except the above), nose, dexy, ipython.

Actually, I wasn't able to install scipy, neither with setuptools, nor with a fresh tar.gz archive. To my surprise, however, the installation of Matplotlib went fine! (I remember having to clean a lot of post-install stuff during my previous install on OS X SL.)

Revised approach (that worked for me)

About scipy, a little googling suggests that the problem may be related to a broken numpy install (through either pip or easy_install), where some files are simply missing (e.g., npymath.ini that scipy complains not to found). So, I tried to compile everything the usual way. First, I cleaned up my fresh numpy install:

$ cd /Library/Python/2.7/site-packages
$ sudo easy_install -m numpy
$ sudo rm -rf numpy-1.6.1-py2.7-macosx-10.7-intel.egg/

(Likewise, I had to remove matplotlib and scikits.learn.)

Then,

  1. Download the latest numpy 1.6.1 from SourceForge.net
  2. Build it,

    $ python setup.py build --fcompiler=gfortran
    $ sudo python setup.py install
    
  3. Check that we now have npymath.ini

Now, let's try installing scipy again. Using pip, I still get an error (about some C code). So, I used the tar.gz source files directly, and

$ sudo python setup.py install

and everything seems to go fine up to the sparse/* stuff where I got error with compilation of veclib_cabi_c.c. This strongly resembles what was described in one of the scipy tickets. It is suggested to just add

#include <complex.h>

at the top of scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_c.c. Now, there is a new error with scipy/linalg/src/fblaswrap_veclib_c.c that I fixed in the same way. And, ô miracle, everything compiled fine till this end where I could read:

Writing /Library/Python/2.7/site-packages/scipy-0.9.0-py2.7.egg-info
running install_clib

I didn't run the test suite, though.

To sum up, to get a working installation of numpy, scipy, matplotlib, and all scientific libraries you want,

  • Install nose via easy_install
  • Install numpy from source
  • Install scipy from source (you'll need to patch veclib_cabi_c.c and fblaswrap_veclib_c.c)
  • Install matplotlib via easy_install

While we are in, let's install cython: it went smoothly with easy_install. Finally, I was able to install the scikits.statsmodels which depends on numpy and scipy, but from the pypi tarball only (the automated install via easy_install seems to hang on a broken git revision). I used:

python setup.py install --with-cython

Below is a little check, using %run example_predict.py in IPython 0.10.2:

scikit

and an illustration with mean shift algorithm, from the scikits.learn:

scikit2

Welcome OS X Lion again: How fortunate!

---

Articles with the same tag(s):

El Capitan
Why I am still using Emacs
Tmux and OS X
OS X Yosemite
Some useful Mac Apps for data scientists
Collecting email usage statistics from mu
From Beamer to Deckset
Fixing some critical keyboard shortcuts in OS X terminal
A modular configuration for Emacs
Common lisp on Mavericks

---