How to install matplotlib on OS X?
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
Related videos on Youtube
bastibe
Updated on September 17, 2022Comments
-
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 usingbrew install pip
I installed numpy 1.5.1 usingpip install numpy
I installed scipy 0.8.0 usingpip 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 directoryThese 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 over 13 yearsTried
brew install freetype
? -
Admin over 13 yearsYeah. That package is not available. There is however a formula on github that provides it. Does not help, though.
-
-
bradley.ayers about 13 yearsHow does one install
pkg-info
? -
bastibe about 13 years@bradley
brew install pkg-info
-
bastibe almost 13 yearsAs 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 almost 13 yearsSorry, that's a typo. I meant 1.1.0.
-
bastibe almost 13 yearsI 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 about 12 yearsActually, I think it should be
pkg-config
, sobrew install pkg-config
. And don't forget tobrew link
it too. -
schlamar over 11 yearsI had pkg-config installed, but it didn't work. bradley.ayers solution worked for me.
-
drootang over 11 yearsMake sure the freetype2.pc file is in a location pkg-config knows to read
-
Tom about 11 yearsbrew install freetype -> Error: No available formula for freetype. Did the name change?
-
LWZ over 10 years
brew install freetype
installslibpng
too.