Unable to install matplotlib on Mac OS X Unable to install matplotlib on Mac OS X python python

Unable to install matplotlib on Mac OS X


The root of the problem is that freetype and libpng are installed in non-canonical locations by XCode, in /usr/X11 instead of /usr or /usr/local.

All of the answers already given address the problem by re-building freetype and libpng, either manually or using a package manager like homebrew.

You can, however, get matplotlib to compile by simply symlinking the existing freetype/libpng headers and libraries into the /usr/local tree with:

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

I prefer to build python packages with pip, so I would then use:

sudo pip install matplotlib

If you don't already have pip, you can install it with easy_install (which comes with OS X):

sudo easy_install pip

I've only tested this on 10.7 (Lion) but I suspect it will also work with 10.6.

It is a little bit of a hack, but I've found it to be the easiest way to get matplotlib installed against the stock python framework that ships with OS X. The stock python framework in 10.7 is actually pretty good, and includes, for instance, a numpy-1.5.1 package that is linked against Apple's optimized BLAS library (Accelerate):

dyldinfo -dylibs /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/linalg/lapack_lite.so for arch x86_64:attributes     dependent dylibs            /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate            /usr/lib/libSystem.B.dylib


Old, but still popped up in my search when I had the same problem on Snow Leopard.

You said you were using homebrew, so you need to

brew link freetype

after installing it (with "brew install freetype").

This got through that error. I had do the same thing with libpng, which resulted in a successful install.


I was given a new work computer recently (MacBook Pro OS 10.6.5), and wanted to install numpy + scipy + matplotlib in a Python virtual environment. I'm not an expert, but the virtual environment seems to allow you to install packages such that they are isolated from the system-wide packages, essentially by redefining the system path in a clever way. So, for one project I am working on that requires certain versions of these packages, I can install them once and do all of my work for that project there, independently of other changes I make outside the environment.

After a lot of trial and error, I was able to build a virtual environment with Numpy 1.5.1, Scipy 0.8.0, and Matplotlib 1.0.0 all running flawlessly. Here's how:

First, install the following four packages:

(I'm a new user so I can't post links to these, sorry!).

If you install from source, use a standard install:

  • $ ./configure
  • $ make
  • $ sudo make install

Next, download the source files for numpy, scipy, and matplotlib.

Now it's time to create a virtual environment in folder TESTENV:

$ virtualenv /path/to/dir/TESTENV

Activate the virtual environment:

$ source . /path/to/dir/TESTENV/bin/activate

Now, python packages will be installed within TESTENV as if it were the root installation directory. What worked for me was to execute:

$ python setupegg.py install

in the numpy, scipy, and matplotlib source folders (in that order).

Hope that helps!