20

I'm trying to install matplotlib for graphing applications in Python on Mac OS X. When I run "python setup.py install", it gives me this load of errors: http://pastebin.com/u7fL37ic.

A quick snippet:

src/ft2font.cpp:2170: error: ‘FT_LOAD_TARGET_MONO’ was not declared in this scope
src/ft2font.cpp:2171: error: ‘FT_LOAD_TARGET_LCD’ was not declared in this scope
src/ft2font.cpp:2172: error: ‘FT_LOAD_TARGET_LCD_V’ was not declared in this scope
src/ft2font.cpp:2175: error: ‘_ft2Library’ was not declared in this scope
src/ft2font.cpp:2175: error: ‘FT_Init_FreeType’ was not declared in this scope
src/ft2font.cpp: In destructor ‘virtual ft2font_module::~ft2font_module()’:
src/ft2font.cpp:2186: error: ‘_ft2Library’ was not declared in this scope
src/ft2font.cpp:2186: error: ‘FT_Done_FreeType’ was not declared in this scope
lipo: can't figure out the architecture type of: /var/folders/Nj/Njnlp9qSF64sMESWcaDnk++++TI/-Tmp-//cchyYmM5.out
error: command 'gcc-4.0' failed with exit status 1

I installed freetype using MacPorts, and I thought that would fix the issue, but no luck. Gives me same error as before. It looks like it can't find the right freetype files:

BUILDING MATPLOTLIB
 matplotlib: 1.0.0
 python: 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) [GCC
 4.0.1 (Apple Inc. build 5493)]
 platform: darwin
REQUIRED DEPENDENCIES
 numpy: 1.5.0
 freetype2: found, but unknown version (no pkg-config)
 * WARNING: Could not find 'freetype2' headers in any
 * of '.', './freetype2'.

Where should I put the freetype files so that they can be found? Right now they're in /opt/local/lib

Any ideas?

asked Nov 4, 2010 at 0:45
1
  • RIP John D. Hunter - author of matplotlib. So sad to hear that he passed away. matplotlib.org Commented Oct 6, 2012 at 6:21

14 Answers 14

34

The root of the problem is that freetype and libpng are installed in non-canonical locations by XCode, in /usr/X11 instead of /usr or /usr/local.

All of the answers already given address the problem by re-building freetype and libpng, either manually or using a package manager like homebrew.

You can, however, get matplotlib to compile by simply symlinking the existing freetype/libpng headers and libraries into the /usr/local tree with:

sudo mkdir -p /usr/local/include
sudo ln -s /usr/X11/include/freetype2/freetype /usr/local/include/freetype
sudo ln -s /usr/X11/include/ft2build.h /usr/local/include/ft2build.h
sudo ln -s /usr/X11/include/png.h /usr/local/include/png.h
sudo ln -s /usr/X11/include/pngconf.h /usr/local/include/pngconf.h
sudo ln -s /usr/X11/include/pnglibconf.h /usr/local/include/pnglibconf.h
sudo mkdir -p /usr/local/lib
sudo ln -s /usr/X11/lib/libfreetype.dylib /usr/local/lib/libfreetype.dylib
sudo ln -s /usr/X11/lib/libpng.dylib /usr/local/lib/libpng.dylib

I prefer to build python packages with pip, so I would then use:

sudo pip install matplotlib

If you don't already have pip, you can install it with easy_install (which comes with OS X):

sudo easy_install pip

I've only tested this on 10.7 (Lion) but I suspect it will also work with 10.6.

It is a little bit of a hack, but I've found it to be the easiest way to get matplotlib installed against the stock python framework that ships with OS X. The stock python framework in 10.7 is actually pretty good, and includes, for instance, a numpy-1.5.1 package that is linked against Apple's optimized BLAS library (Accelerate):

dyldinfo -dylibs /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/linalg/lapack_lite.so 
for arch x86_64:
attributes dependent dylibs
 /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
 /usr/lib/libSystem.B.dylib
answered Jun 1, 2012 at 1:54
4
  • this is the only way from which I tried that worked for me (don't want to pay for EPD), thanks! Commented Aug 19, 2012 at 19:03
  • 8
    UPDATE: in OS X Mountain Lion (10.8), X11 is no longer installed by default, and you need to install XQuartz instead (see support.apple.com/kb/HT5293). The good news is that I found an even simpler way to install matplotlib without creating symlinks into /usr/local. If you have pkg-config installed (for instance through homebrew), run "sudo PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig pip install matplotlib" which will then pickup the correct dependencies (libpng, freetype) from XQuartz via pkg-config. Commented Sep 11, 2012 at 16:39
  • The above method (with PKG_CONFIG_PATH) didn't work for me on 10.8.4. Commented Jun 19, 2013 at 22:57
  • 3
    UPDATE: MacOS X Mavericks now installs these items in /opt/X11 not /usr/X11, so by (a) re-installing the XCode cmd line tools, then following the above recipe changing the source path in each of the ln -s commands, I was able to install matplotlib. Commented Mar 21, 2014 at 0:37
10

Old, but still popped up in my search when I had the same problem on Snow Leopard.

You said you were using homebrew, so you need to

brew link freetype

after installing it (with "brew install freetype").

This got through that error. I had do the same thing with libpng, which resulted in a successful install.

answered Oct 10, 2012 at 0:31
7

I was given a new work computer recently (MacBook Pro OS 10.6.5), and wanted to install numpy + scipy + matplotlib in a Python virtual environment. I'm not an expert, but the virtual environment seems to allow you to install packages such that they are isolated from the system-wide packages, essentially by redefining the system path in a clever way. So, for one project I am working on that requires certain versions of these packages, I can install them once and do all of my work for that project there, independently of other changes I make outside the environment.

After a lot of trial and error, I was able to build a virtual environment with Numpy 1.5.1, Scipy 0.8.0, and Matplotlib 1.0.0 all running flawlessly. Here's how:

First, install the following four packages:

(I'm a new user so I can't post links to these, sorry!).

If you install from source, use a standard install:

  • $ ./configure
  • $ make
  • $ sudo make install

Next, download the source files for numpy, scipy, and matplotlib.

Now it's time to create a virtual environment in folder TESTENV:

$ virtualenv /path/to/dir/TESTENV

Activate the virtual environment:

$ source . /path/to/dir/TESTENV/bin/activate

Now, python packages will be installed within TESTENV as if it were the root installation directory. What worked for me was to execute:

$ python setupegg.py install

in the numpy, scipy, and matplotlib source folders (in that order).

Hope that helps!

answered Jan 20, 2011 at 6:45
0
4

Try the instuctions here. My notes here.

answered Nov 14, 2010 at 20:16
1
  • This didn't work for me - I think its b/c I'm using a version of python installed in /usr/local (via brew)...probably works for the standard python installed with OSX Snow Leopard I'm guessing. Commented Sep 27, 2011 at 21:24
4

I was having the same problem when trying to install matplotlib. After trying some of the above solution, I just ran

brew install freetype

then, the installation went well until it ran into a png.h not found. I ran

brew install libpng

The installation finished and matplotlib was installed.

(on os X 10.8.4)

answered Aug 10, 2013 at 13:33
2
  • That's the easiest way to do it. Works fine on 10.9 as well. Commented Feb 12, 2014 at 9:27
  • works like a charm on 10.15 no error after installing freetype Commented Nov 6, 2019 at 15:03
3

Here's how I did it:

$ sudo make -f make.osx fetch deps mpl_build mpl_install

This will install it in /lib/python2.6/site-packages, just move its contents to /Library/Python/2.6/site-packages/ for consistency.

answered Nov 16, 2010 at 11:45
1
  • Hey, tried running this and got this error: IOError: [Errno socket error] [Errno 51] Network is unreachable make: *** [fetch] Error 1 Thoughts? Commented Nov 30, 2010 at 5:43
2

I got a similar error - you're missing the development files for libfreetype - on my linux machine - this is libfreetype6-dev

After I installed this pip did it's job.

answered May 2, 2012 at 3:52
2

Running into this every time I build matplotlib. My solution:

export CFLAGS=-I/usr/X11/include/freetype2
python setup.py install
answered Jul 29, 2013 at 18:35
2

I would highly recommend the StrongInference Scipy Superpack. It works with the built-in Apple supplied Python on 10.6 Snow Leopard, and this is now working with 10.9. It's friendly to both 32-bit and 64-bit installs. It does not require installing a separate Python distribution or package managers like Macports or Fink.

Use it by first downloading the shell script from this page. Then:

sh superpack_10.6_2011年03月07日.sh

Or, replace superpack_10.6_2011年03月07日.sh with the name of the latest shell script as they update it from time to time.

To use it, make sure you type in ipython and not python!

answered Feb 24, 2011 at 21:39
2
  • The StrongInference Superpack folks have updated their script for Lion as well. Commented Aug 23, 2011 at 0:43
  • Denis, I fixed the broken (the page moved) link. Thanks! Commented Jan 8, 2013 at 7:36
1

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 0.10.0 dev (as of this writing) and path /usr/local/Cellar/...

answered Aug 16, 2011 at 20:26
1

I like using the brew, and none of the top three explanations worked or were enticing to me. However, I did look some more, and found this brew friendly explanation and solution:

http://jholewinski.org/blog/installing-matplotlib-on-os-x-10-7-with-homebrew/

Summary: libpng on Snow Leopard isn't on friendly terms with matplotlib. You can manually install the un-released matplotlib to work around it:

brew install python
brew install gfortran
brew install pkg-config
easy_install pip
pip install numpy
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install
hamish
3503 silver badges11 bronze badges
answered Sep 27, 2011 at 21:23
1

Try symlinking freetype2 to freetype:

ln -s /usr/local/opt/freetype/include/freetype2/ /usr/local/include/freetype
answered Dec 24, 2013 at 5:51
0

you may also consider using the Enthought distribution (which comes even free for non-commercial usage) It comes fully installed without any difficulty http://www.enthought.com/products/getepd.php (I have no relationship with Enthought whatsoever - I'm just a satisfied user)

answered Nov 15, 2010 at 16:34
1
  • Too bad this is checked as an answer because it just does not answer the question... see answer below from @mhowison Commented Jan 11, 2017 at 20:22
0

I was able to get this to work without modifying my PATH etc. It seems my problem was the freetype library (installed with brew) not being found when using a non-brew python

brew install python
brew install freetype
# maybe more dependencies

Then create a virtualenv using the brew python (without explicitly specifying the path to the brew python I found that the brew virtualenv would still use the default OSX /usr/bin/python):

/usr/local/bin/virtualenv -p /usr/local/bin/python env
source env/bin/activate
pip install matplotlib
answered Jul 9, 2015 at 15:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.