I have been trying to install the excellent MatPlotLib graphing module for the Python programming language on my iMac for a while now. Unlike most python module installations I’ve done the excellent python SetupTools (a.k.a easy_install) has not been up to the task.  So I ended up using MacPorts (version 1.8.1) to get MatPlotLib (version 0.99.1.1) installed on Snow Leopard (OS X 10.6.2) with X-Code (3.2.1 – 1613).

So here is a brief description of how to do it:

  1. Install the X-Code developer tools (for GCC, make and other build tools) from your Snow Leopard installation DvD.
  2. Install the X11 Window System from your Snow Leopard installation DvD.
  3. Run ‘Software Update‘ from the apple menu on your Mac to get the latest X-Code updates.
  4. Download the latest MacPorts installer (.dmg file extension) for Snow Leopard from here: http://distfiles.macports.org/MacPorts/.
  5. Mount the installer image file (.dmg) and run the contained MacPorts installer (.pkg).
  6. Once installation is complete open a terminal window from Applications->Utilities->Terminal.
  7. Type ‘port‘ at the terminal then press enter to run MacPorts.  You should see output like the following if it installed correctly:
    MacPorts 1.8.1
    Entering interactive mode… (“help” for help, “quit” to quit)

    Then type ‘quit‘ then press enter to exit port’s interactive mode.
  8. Type ‘sudo port selfupdate‘ and press enter to update MacPorts to the latest version.  You will be asked to enter the administrators password before continuing.  Depending on how new the version you downloaded is, MacPorts may do some upgrading.
  9. Once the update is finished type ‘sudo port install py26-matplotlib‘ and press enter.  This will attempt to install the latest version of matplotlib for Python version 2.6.*.   You may be asked to enter the administrators password before continuing.  MacPorts will now download, configure, build and stage the dependencies needed to build the latest matplotlib for Python 2.6.  This took at least thirty minutes on my iMac and involved lots and lots of scrolling text output from the build process.
  10. Next we need to switch our environment to use version 2.6.* of Python that MacPorts just built and installed with matplotlib.  To do this run the following two commands, note you may be asked to enter the administrators password before continuing:
    1. sudo port install python_select‘ and hit enter.
    2. sudo python_select python26‘ and hit enter.
  11. To test this all worked type the following: ‘python -V’ and hit enter.  You should see output like ‘Python 2.6.4‘ which should match the version of python MacPorts built and installed.
  12. Finally to test if matplotlib was installed correctly do the following:
    1. Type ‘python‘ and hit enter to enter the python interactive shell.
    2. Type ‘import matplotlib‘ and hit enter, this will import the matplotlib module.  There should be no output if this works.
    3. Type ‘print matplotlib.__version__‘ and hit enter. This will print the version of matplotlib that is installed, you should see output like ‘0.99.1.1‘.
    4. Type ‘exit()‘ to quit the python interactive shell.