Installing NumPy and matplotlib on OS X

Given that OS X provides you with Python, you would expect it to be easy to install Python libraries on a modern Mac. Unfortunately, that’s not always true. Case in point: NumPy and matplotlib. These are my favorite tools nowadays for generic scientific computation and visualization. Going through the process of getting them to work for the nth time on a Mac, I decided to document the easiest way I found to do it, for my own future reference and in the hope that it helps someone.

Disclaimer: I’m doing this installation on Leopard (OS X 10.5) with Python 2.6.*. I assume the same procedure applies to later versions of OS X (yes, I’m a late adopter) and the Python 2 series.

I think if you have a good understanding of computer software then you really will have not trouble what so ever with this. Using a high speed internet connection, perhaps broadband from O2 or from elsewhere then you will be capable of downloading the following. It was important to me to find the easiest way of doing this. No one wants to spend hours installing software and hopefully with my help you won’t have to.

So there are many ways to go about it, but this is the simplest one I found. It’s completely based on binary .dmg files:

Step 1: Download and install the latest “Python 2.6.* Mac OS X Installer Disk image” from the official python.org download pages.

This gives you an up-to-date python installation that doesn’t interfere with the system’s one.
To test, type

python --version

on the command line, and the version of Python you just installed should be reported.

Step 2: Download and install the latest Numerical Python .dmg binary for OS X and Python 2.6 from NumPy’s sourceforge download page.

To test, start a python interpreter and try this:

>>> import numpy
>>> numpy.__version__

Step 3: Download and install the latest matplotlib .dmg binary for OS X and Python 2.6 from matplotlib’s sourceforge download page.

To test, start a python interpreter and try this:

>>> import matplotlib
>>> matplotlib.__version__

Et voilá, this should do the trick.

Extra tip: If you use the shebang:

#!/usr/bin/env python

instead of:

#!/usr/bin/python

the version of python you want will be automatically used when you run your script from the command line.

This entry was posted in Python, Science, Tech Stuff and tagged , , , , , , . Bookmark the permalink.

2 Responses to Installing NumPy and matplotlib on OS X

  1. Miguel says:

    Well… on a “real” OS you can just do:

    emerge numpy madplotlib

    and that’s it.

    You can also play a bit with USE flags so that you can customize the installation: for example to have matplotlib using traits ( http://code.enthought.com/projects/traits ).

    Now.. wich one is easier?

  2. Yes, I do miss Gentoo sometimes. The part I don’t miss is having to deal with drivers, sudden breakages, etc. Nothing’s perfect, I guess.

    To be fair, you can do the same thing on a mac with macports. I use it for all sorts of things, but it never seems to work out for me in this case.

    I will definitely go back to Linux if Apple decides to apply their iPhone/iPad-like restrictive policies to laptops.

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>