views:

2567

answers:

6

I've killed half a day trying to compile matplotlib for python on Snow Leopard. I've used the googles and found this helpful page (http://blog.hyperjeff.net/?p=160) but I still can't get it to compile. I see comments from other users on that page, so I know I'm not alone.

I already installed zlib, libpng and freetype independently.

I edited the make.osx file to contain this at the top:

PREFIX=/usr/local

PYVERSION=2.6
PYTHON=python${PYVERSION}
ZLIBVERSION=1.2.3
PNGVERSION=1.2.33
FREETYPEVERSION=2.3.5
MACOSX_DEPLOYMENT_TARGET=10.6

## You shouldn't need to configure past this point

PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-Os -arch x86_64 -arch i386 -I${PREFIX}/include"
LDFLAGS="-arch x86_64 -arch i386 -L${PREFIX}/lib"
CFLAGS_DEPS="-arch i386 -arch x86_64 -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX10.6.sdk"
LDFLAGS_DEPS="-arch i386 -arch x86_64 -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX10.6.sdk"

I then run:

sudo make -f make.osx mpl_build

which gives me:

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" &&\
    export MACOSX_DEPLOYMENT_TARGET=10.6 &&\
    export CFLAGS="-Os -arch x86_64 -arch i386 -I/usr/local/include" &&\
    export LDFLAGS="-arch x86_64 -arch i386 -L/usr/local/lib" &&\
    python2.6 setup.py build

... snip ...

gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -Os -arch x86_64 -arch i386 -I/usr/local/include -pipe -DPY_ARRAYAUNIQUE_SYMBOL=MPL_ARRAY_API -I/Library/Python/2.6/site-packages/numpy/core/include -I. -I/Library/Python/2.6/site-packages/numpy/core/include/freetype2 -I./freetype2 -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/ft2font.cpp -o build/temp.macosx-10.6-universal-2.6/src/ft2font.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++
In file included from src/ft2font.h:13,
                 from src/ft2font.cpp:1:
/usr/local/include/ft2build.h:56:38: error: freetype/config/ftheader.h: No such file or directory

... snip ...

src/ft2font.cpp:98: error: ‘FT_Int’ was not declared in this scope
/Library/Python/2.6/site-packages/numpy/core/include/numpy/__multiarray_api.h:1174: warning: ‘int _import_array()’ defined but not used
lipo: can't open input file: /var/tmp//ccDOGx37.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1
make: *** [mpl_build] Error 1

I'm just lost.

A: 

Try with this one: http://macinscience.org/?page%5Fid=6 or as an alternative, with easy_install.

dalloliogm
Thanks for the link, but judging from the comments on that page, it doesn't seem that superpack works with Snow Leopard.
Greg
and have you tried with enthought (http://www.enthought.com/products/epd.php)? It is free for academic usage.
dalloliogm
I'm no longer an academic so it won't be free for me. And I don't like the idea of paying just to figure out how to compile something.
Greg
+4  A: 

According to your error message you have missing freetype headers. Can you locate them using system search functionalities. I will not lecture on using a pre-built package since I love scratching my head and compiling from the start as well.

whatnick
Thanks whatnick. That helped me edit the make.osx makefile.
Greg
A: 

I just got it to compile. I added freetype2 in the include path for the CFLAGS in the make.osx file. Now the top of make.osx is:

PREFIX=/usr/local

PYVERSION=2.6
PYTHON=python${PYVERSION}
ZLIBVERSION=1.2.3
PNGVERSION=1.2.33
FREETYPEVERSION=2.3.5
MACOSX_DEPLOYMENT_TARGET=10.6

## You shouldn't need to configure past this point

PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-Os -arch x86_64 -arch i386 -I${PREFIX}/include -I${PREFIX}/include/freetype2"
LDFLAGS="-arch x86_64 -arch i386 -L${PREFIX}/lib"
CFLAGS_DEPS="-arch i386 -arch x86_64 -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX10.6.sdk"
LDFLAGS_DEPS="-arch i386 -arch x86_64 -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX10.6.sdk"

Then I ran these commands, and it compiled and installed perfectly.

sudo make -f make.osx mpl_build
sudo make -f make.osx mpl_install
Greg
Well then I got answer - spot on.
whatnick
You sure did -- thanks a lot whatnick!
Greg
A: 

You should really ask this on the matplotlib-users mailing list. It's monitored by actual matplotlib developers, which StackOverflow (AFAIK) isn't.

dwf
+2  A: 

You can also build by using

$ python setup.py build

with the following patch applied to setupext.py

Index: setupext.py
===================================================================
--- setupext.py (revision 7917)
+++ setupext.py (working copy)
@@ -334,6 +334,8 @@

     module.include_dirs.extend(incdirs)
     module.include_dirs.append('.')
+    module.include_dirs.append('/usr/local/include')
+    module.include_dirs.append('/usr/local/include/freetype2')
     module.library_dirs.extend(libdirs)

 def getoutput(s):
celil
This worked for me.
Markus
A: 

as suggested elsewhere, macports works fine on multiple architecture and versions of MacOsX + allows updates and more:

$ port search matplot
py-matplotlib @0.99.0 (python, graphics, math)
    matlab-like syntax for creating plots in python

py-matplotlib-basemap @0.99.4 (python, graphics, math)
    matplotlib toolkit for plotting data on map projections

py25-matplotlib @0.99.0 (python, graphics, math)
    matlab-like syntax for creating plots in python

py25-matplotlib-basemap @0.99.4 (python, graphics, math)
    matplotlib toolkit for plotting data on map projections

py26-matplotlib @0.99.0 (python, graphics, math)
    matlab-like syntax for creating plots in python

py26-matplotlib-basemap @0.99.4 (python, graphics, math)
    matplotlib toolkit for plotting data on map projections

Found 6 ports.
$

in your case, simply issue :

$ sudo port install py26-matplotlib

it features the macosx backend (native cocoa) as default

meduz