How to install matplotlib on OS X?

25,726

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 4

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

Solution 5

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

brew install freetype
Share:
25,726

Related videos on Youtube

bastibe
Author by

bastibe

Updated on September 17, 2022

Comments

  • bastibe
    bastibe over 1 year

    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?

    • Admin
      Admin over 13 years
      Tried brew install freetype ?
    • Admin
      Admin over 13 years
      Yeah. That package is not available. There is however a formula on github that provides it. Does not help, though.
  • bradley.ayers
    bradley.ayers about 13 years
    How does one install pkg-info?
  • bastibe
    bastibe about 13 years
    @bradley brew install pkg-info
  • bastibe
    bastibe almost 13 years
    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.
  • David Xia
    David Xia almost 13 years
    Sorry, that's a typo. I meant 1.1.0.
  • bastibe
    bastibe almost 13 years
    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.
  • noio
    noio about 12 years
    Actually, I think it should be pkg-config, so brew install pkg-config. And don't forget to brew link it too.
  • schlamar
    schlamar over 11 years
    I had pkg-config installed, but it didn't work. bradley.ayers solution worked for me.
  • drootang
    drootang over 11 years
    Make sure the freetype2.pc file is in a location pkg-config knows to read
  • Tom
    Tom about 11 years
    brew install freetype -> Error: No available formula for freetype. Did the name change?
  • LWZ
    LWZ over 10 years
    brew install freetype installs libpng too.