Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

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

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

    
Tried brew install freetype ? –  ismail 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. –  bastibe Feb 3 '11 at 12:48
1  
brew install freetype worked for me as of 7-Nov-2012 –  drootang Nov 8 '12 at 16:30
add comment

6 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
share|improve this answer
add comment
up vote 10 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.

share|improve this answer
    
How does one install pkg-info? –  bradley.ayers Apr 6 '11 at 1:57
    
@bradley brew install pkg-info –  bastibe Apr 10 '11 at 12:28
4  
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 '12 at 14:14
    
I had pkg-config installed, but it didn't work. bradley.ayers solution worked for me. –  schlamar Oct 21 '12 at 19:21
    
Make sure the freetype2.pc file is in a location pkg-config knows to read –  drootang Nov 8 '12 at 18:08
add comment

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

brew install freetype
share|improve this answer
    
brew install freetype -> Error: No available formula for freetype. Did the name change? –  Tom Apr 10 '13 at 22:23
1  
brew install freetype installs libpng too. –  LWZ Dec 11 '13 at 19:37
add comment

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/...

share|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. –  bastibe Aug 17 '11 at 7:34
    
Sorry, that's a typo. I meant 1.1.0. –  David Xia Aug 17 '11 at 8:45
add comment

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.

share|improve this answer
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 '11 at 9:58
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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