Installing matplotlib on OS X 10.7 Lion

1 reply [Last post]
User offline. Last seen 4 days 1 hour ago. Offline
Joined: 08/15/2010

matplotlib is a great python package for visualizing data. It is, unfortunately, a pain to install on OS X (on Ubuntu it is as simple as sudo apt-get install python-matplotlib).

We recently had to address this to simplify installation of Agalma, the tool we wrote to automate transcriptome assembly from Illumina data and collect a variety of diagnostics (

The problem with installing matplotlib on OS X is that there are a few dependencies that are already installed on OS X Lion, but not in a place where python expects to find them (instead, they are in among the X11 support files). As explained in the Agalma INSTALL file, you can fix this by making links to the files in a location where python will look for them. These commands take care of this:

sudo mkdir -p /usr/local/include
sudo ln -s /usr/X11/include/freetype2/freetype /usr/local/include/freetype
sudo ln -s /usr/X11/include/ft2build.h /usr/local/include/ft2build.h
sudo ln -s /usr/X11/include/png.h /usr/local/include/png.h
sudo ln -s /usr/X11/include/pngconf.h /usr/local/include/pngconf.h
sudo ln -s /usr/X11/include/pnglibconf.h /usr/local/include/pnglibconf.h
sudo mkdir -p /usr/local/lib
sudo ln -s /usr/X11/lib/libfreetype.dylib /usr/local/lib/libfreetype.dylib
sudo ln -s /usr/X11/lib/libpng.dylib /usr/local/lib/libpng.dylib

Once you make these links, you can use the old python package manager easy_install to install the new python package manager pip, and then use pip to install matplotlib:

sudo easy_install pip
sudo pip install matplotlib

Unfortunately, this will probably break in the next version of OS X (10.8 Mountain Lion), since it will no longer come with X11 and associated files.

User offline. Last seen 22 weeks 4 days ago. Offline
Joined: 08/04/2010
Installing matplotlib on OSX 10.8 (Mountain Lion)

The instructions above work equally well for Mountain Lion, as long as you first install X11 from this site: