Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to install matplotlib on Mac OS X

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?

like image 764
tchaymore Avatar asked Nov 04 '10 00:11

tchaymore


People also ask

How do I download matplotlib for Python on Mac?

The easiest way to get matplotlib on Mac OS X is to use prepackaged python distributions such as Enthought Python Distribution (EPD). Just go to the EPD site and download and install the latest stable version for your OS.

Does Python 3.10 support matplotlib?

Matplotlib 2.0. x supports Python versions 2.7 through 3.10. Python 3 support started with Matplotlib 1.2.

How do I check my matplotlib version on Mac?

Once you've successfully installed matplotlib, you can use the following command to display the matplotlib version in your environment: pip show matplotlib Name: matplotlib Version: 3.1.


1 Answers

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
like image 109
mhowison Avatar answered Oct 18 '22 14:10

mhowison