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?

link|improve this question

74% accept rate
Tried brew install freetype ? – İsmail 'cartman' Dönmez Feb 3 '11 at 12:18
Yeah. That package is not available. There is however a formula on github that provides it. Does not help, though. – Paperflyer Feb 3 '11 at 12:48
feedback

migrated from stackoverflow.com Feb 6 '11 at 1:34

This question came from our site for professional and enthusiast programmers.

4 Answers

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
link|improve this answer
feedback
up vote 2 down vote accepted

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

link|improve this answer
How does one install pkg-info? – bradley.ayers Apr 6 '11 at 1:57
@bradley brew install pkg-info – Paperflyer Apr 10 '11 at 12:28
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 at 14:14
feedback

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:

python
import matplotlib
print matplotlib.__version__
print matplotlib.__file__

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

link|improve this answer
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. – Paperflyer Aug 17 '11 at 7:34
Sorry, that's a typo. I meant 1.1.0. – David Xia Aug 17 '11 at 8:45
feedback

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.

link|improve this answer
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. – Paperflyer Aug 17 '11 at 9:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.