Setting up a Python Scientific Environment (NumPy, SciPy, pandas, StatsModels, etc.) in OS X 10.9 Mavericks

It is better than a nightmare from which you cannot wake up ...

  1. Install Homebrew:

    $ ruby -e "$(curl -fsSL"
  2. Find problems and fix them (typically resulting from Homebrew becoming very stroppy if it does not have exclusive access to "/usr/local"):

    $ brew doctor

    VERY IMPORTANT NOTE: Make ABSOLUTELY sure that the DYLD_LIBRARY_PATH environmental variable is NOT set. Having this set will cause all sorts of problems as conflicts arise between libraries that homebrew installs that some of your other packages need (e.g., "libpng" and MacVim, respectively). Worse, some builds get confused and fail (e.g., "matplotlib"). What happens if you need DYLD_LIBRARY_PATH for other applications? Please direct your questions to the homebrew folks.

  3. Install Homebrew's Pythons:

    $ brew install python
    $ brew install python3
  4. Either create and source a virtual environment using Homebrew's Python:

    $ virtualenv -p /usr/local/python3 homebrew-stats-computing
    $ . homebrew-stats-computing/bin/activate

    Or make sure Homebrew's Python is at the head of the "$PATH":

    $ export PATH=/usr/local/bin:$PATH
  5. Install The NumPy + SciPy + pandas stack:

    $ brew install gfortran
    $ pip3 install numpy
    $ pip3 install scipy
    $ pip3 install pandas
  6. Install StatsModels:

    $ pip3 install cython
    $ pip3 install patsy
    $ cd /tmp
    $ git clone
    $ cd statsmodels
    $ python3 build
    $ python3 install
  7. Install matplotlib:

    $ brew install libpng freetype pkgconfig
    $ cd /tmp
    $ git clone
    $ cd matplotlib
    $ python3 install

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>