Error while installing matplotlib

Question:

I’ve tried using pip install matplotlib and git clone then python setup.py install as described in the installation faq for Mac OS 10.7. But I get the same error:

[...]
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -I. -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/freetype2 -I./freetype2 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/ft2font.cpp -o build/temp.macosx-10.7-intel-2.7/src/ft2font.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
In file included from src/ft2font.cpp:3:
src/ft2font.h:16:22: error: ft2build.h: No such file or directory
src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:20:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:21:10: error: #include expects "FILENAME" or <FILENAME>
In file included from src/ft2font.cpp:3:
src/ft2font.h:34: error: ‘FT_Bitmap’ has not been declared
src/ft2font.h:34: error: ‘FT_Int’ has not been declared
src/ft2font.h:34: error: ‘FT_Int’ has not been declared
src/ft2font.h:86: error: expected ‘,’ or ‘...’ before ‘&’ token
[...]

It seems like I’m missing some package installed in my system? Or there any other better way to install matplotlib?

Thanks!

UPDATE: by googling and search on SO I’ve found that I might lack the package freetype2, however, if I try to install it by homebrew I get a warning message:

[me @ my mac]$ brew search freetype
Apple distributes freetype with OS X, you can find it in /usr/X11/lib.
However not all build scripts look here, so you may need to call ENV.x11
in your formula's install function.
Asked By: clwen

||

Answers:

Same error, the install worked on one of my Lion machines but not the other. Tracked it down to a missing pkg-config

$ brew install pkg-config
$ pip install -U 'http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz/download'

(see also https://jholewinski.org/blog/installing-matplotlib-on-os-x-10-7-with-homebrew/ )

Answered By: jon

Thanks for the link above. I was able to get matplotlib working with some minor changes. I am documenting the specific error message I ran into, for future reference.

Env:
Mac OS X 10.7.4 (Lion) running stock python 2.7.1 (found in /usr/bin)

I started out trying to get matplotlib working against the default install. setup.py hinted at some problems specifically:

freetype2: found, but unknown version (no pkg-config)
                        * WARNING: Could not find 'freetype2' headers in any
                        * of '.', './freetype2'.

and

OPTIONAL BACKEND DEPENDENCIES
                libpng: found, but unknown version (no pkg-config)
                        * Could not find 'libpng' headers in any of '.'

the setup step would fail with the following error message:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/numpy/__multiarray_api.h:1187: warning: ‘int _import_array()’ defined but not used
lipo: can't open input file: /var/tmp//ccG28dDI.out (No such file or directory)

Googling for this file did not help with anything. I dug around a bit and decided it was not worth my time to go down the virtualenv route.

I ended up following the steps outlined in the jholewinski link above. Installed a new python 2.7.4 in /usr/local/ and followed the instructions there. (I re-installed pkg-config).
I was able to pull the latest version of matplotlib from git and it worked just fine.

Both the libpng (1.5.4) and freetype2 (13.2.7) libraries were present this time.

Answered By: Amar

I had this issue on Ubuntu server 12.04.

I had to install libfreetype6-dev and libpng-dev from the repositories. I was using a virtualenv and installing matplotlib using pip when I ran into this issue.

Hints that I needed to do this came from the warning messages that popup early in the matplotlib installation so keep an eye out for those messages which indicate a dependency is found, but not the headers.

Answered By: Javier Rosa
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.