I want to install matplotlib on OS X. If possible, using homebrew.

I installed Python 2.7.1 using brew install python, I modified my path to use it
I installed pip using brew install pip
I installed numpy 1.5.1 using pip install numpy
I installed scipy 0.8.0 using pip install scipy

This is where it gets hairy. pip install matplotlib will fetch the wrong version of matplotlib, which is incompatible with the recent version of numpy.

The solution is to fetch the correct version of matplotlib manually:

pip install -f http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.0.1/matplotlib-1.0.1.tar.gz matplotlib

But, that version fails to compile since it can't find the freetype headers:

In file included from src/ft2font.cpp:1:
src/ft2font.h:14:22: error: ft2build.h: No such file or directory

These headers are actually installed in /usr/X11/include as part of the X11 developer tools.

So, how can I make matplotlib use these headers?

  • Tried brew install freetype ?
    – ismail
    Feb 3, 2011 at 12:18
  • Yeah. That package is not available. There is however a formula on github that provides it. Does not help, though.
    – bastibe
    Feb 3, 2011 at 12:48
  • 1
    brew install freetype worked for me as of 7-Nov-2012
    – drootang
    Nov 8, 2012 at 16:30

10 Answers 10


The problem is that when the C extensions are compiled, required headers files aren't in the search path, and when they're being linked, shared libraries aren't in the search path either.

The following worked for me:

export LDFLAGS="-L/usr/X11/lib"
export CFLAGS="-I/usr/X11/include -I/usr/X11/include/freetype2 -I/usr/X11/include/libpng12"
pip install matplotlib-1.0.1.tar.gz

The simple answer is: You need to have pkg-info installed or else setup.py won't be able to find installed libraries.

  • 1
    How does one install pkg-info? Apr 6, 2011 at 1:57
  • @bradley brew install pkg-info
    – bastibe
    Apr 10, 2011 at 12:28
  • 7
    Actually, I think it should be pkg-config, so brew install pkg-config. And don't forget to brew link it too.
    – noio
    Mar 27, 2012 at 14:14
  • I had pkg-config installed, but it didn't work. bradley.ayers solution worked for me.
    – schlamar
    Oct 21, 2012 at 19:21
  • Make sure the freetype2.pc file is in a location pkg-config knows to read
    – drootang
    Nov 8, 2012 at 18:08

I followed this page's instructions. I got stuck at

pip install -e git+https://github.com/matplotlib/matplotlib#egg=matplotlib-dev

Then I did:

git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install

Checked my installation by typing in terminal:

import matplotlib
print matplotlib.__version__
print matplotlib.__file__

I got version 1.1.0 (as of this writing) and path /usr/local/Cellar/...

  • As of today, Matplotlib should be at version 1.0.1. I actually wrote something about this here. Maybe you can find some useful information in there.
    – bastibe
    Aug 17, 2011 at 7:34
  • Sorry, that's a typo. I meant 1.1.0.
    – David Xia
    Aug 17, 2011 at 8:45

Altneratively, you could use MacPorts or Fink. With MacPorts this would be

sudo port install py27-matplotlib

which resolves the dependencies automatically.

Personally I used Macports to install python2.7 with matplotlib and it seems to works fine on 10.7. Fink is in the process of upgrading their internals to work with the new 10.7 build system.

  • 1
    I personally prefer Homebrew to MacPorts or Fink since it relies on system libs and is way more hackable. If you don't care about that, using MacPorts or Fink is probably the easiest solution.
    – bastibe
    Aug 17, 2011 at 9:58

The answer is, there's no freetype library. just simply brew it:

brew install freetype
  • brew install freetype -> Error: No available formula for freetype. Did the name change?
    – Tom
    Apr 10, 2013 at 22:23
  • 1
    brew install freetype installs libpng too.
    – LWZ
    Dec 11, 2013 at 19:37

with OS X 10.10.3 I fixed it with this commands

brew install freetype libpng pkg-config

pkg-config fixed the issue!

After reading this issue I manage to fix it


Same problem using macports. Fixed with:

sudo port install pkgconfig

as noio suggested for brew above.


I found this to work flawlessly on OS X 10.8.3 http://penandpants.com/install-python/


These days, the easiest way is probably conda install matplotlib, using the conda package manager by continuum analytics.

Note that you can install and use conda without having to use the full Anaconda distribution. Just pip install conda, conda init, and you're good to go.


I wrote this same reply here but I think it can be of some interest in this discussion.

I got to install matplotlib on OSX 10.10 reading https://github.com/matplotlib/matplotlib/pull/3713.
This is not a solution for pip users; just a way to install matplotlib on my mac waiting for a fix.

I downloaded sources for matplotlib 1.4.2,
changed line 960 in setupext.py as described in https://github.com/matplotlib/matplotlib/pull/3713/files :

'freetype2', 'ft2build.h',


'freetype2', 'freetype2/ft2build.h'

and then compiled and installed with:

python setup.py build
python setup.py install

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .