I put instructions for how to do this in my package for OS-X-10.3, py2.3.0. Here they are. If you do all this, you can donate the package to Bob's repository on pythonmac.org.
There is a related thread about defining a standard way to do this for matplotlib, so it will build out of the box.
They should work just fine for newer versions of OS, matplotlib, and python. Sorry they are a bit wordy:
Here are my notes as to what it took to get matplotlib (0.71) installed and working on OS-X. I have so far kept a fink-free system, so that's what I've done here as well. I use it with the AGG back end for generating images for a web site, and hopefully with the wx backend for interactive use and embedding in wx Applications. I've also quickly got it working with TK. Note that this is kind of a running commentary, not well edited. I'd read the whole thing before starting.
···
-------------------------------------------
According to the matplotlib install docs (http://matplotlib.sourceforge.net/installing.html), you need the following:
freetype (>= 2.1.7)
libpng
zlib
Personally, I've been avoiding Fink, as it doesn't seem to play well with the rest of OS-X, including the Apple supplied Python, so I've looked elsewhere for these libs.
a) Freetype:
I seem to have it in:
/usr/X11R6/include/freetype2
I don't think I installed it myself, so it probably came with Apple's X11, Which I did install.
However, I seemed to be having problems with that version, so I looked, and it seems to be:
libfreetype.6.3.dylib
Given that freetype2 is currently at version 2.1.9, I have no idea what to make of that! So off to sourceforge to get a new freetype:
where I got:
freetype-2.1.9.tar.gz
Following the instructions in docs/INSTALL.UNX:
\./configure
make
$ sudo make install
That puts it in /usr/local/..., which is a good place for it.
NOTE: The above will build freetype as a shared library, which is fine if you are building ot run on the same system you are building on. However, if you want to buuild a re-distributable package, you'll need a static library, which you can get by doing:
\./configure \-\-disable\-shared \-\-enable static
make
$ sudo make install
Hmm. that made the static libs (*.a) , but also the dynamic ones.
Make sure to do:
$ make clean
if you had already built it. You may also have to remove the shared libs, so that they won't be found (*.dyld). I had to remove them from /usr/local/lib.
b) zlib:
I have:
/usr/include/zlib.h
I don't know where I might have gotten it, but there it is.
NOTE: I checked on another system in my office, and it doesn't have zlib. It does, however have libz, which I am told is the same thing, to you shouldn't need this.
c) libpng:
This, I didn't have on my system, except inside the wxWidgets source tree, so I went looking for it.
Note that you need zlib to compile libpng, so make sure you have that first.
I did a google search for "libpng OS-X". I found:
http://www.libpng.org/pub/png/pngcode.html
Which led me to the libpng sourceforge site.
From there I downloaded:
libpng-1.2.8.tar.gz
unpacked it, and opened a terminal in the libpng-1.2.8 directory, and did:
$ cp scripts/makefile.darwin ./makefile
(note that according to the INSTALL, there is supposed to be a makefile.macosx, but it wasn't there)
I took a look in the makefile, and found:
ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include
Which is not where zlib is on my system. However, while I can find zlib.h, I couldn't fine the actual lib, so I tried make without changing anything.
$ make
Which seemed to work fine. zlib must be installed in a standard location, and gcc found it.
$ sudo make install
to install the lib into /usr/local/ (this was specified in the makefile, and it's a good place for it)
make test
and
./pngtest pngnow.png
Which both seemed to pass.
If you want to build a re-distributable version of matplotlib, you need the static version of libpng, instead of the dynamic one. It doesn't use ./configure, so instead, I did a:
sudo make install-static
and that installed the *.a files in /usr/local/lib.
d) Numeric or numarray:
I already have Numeric installed, from Bob Ippolito's PIMP (MacPython Package Manager) repostitory. (www.undefined.org/python)
2) Building matplotlib
---------------------------------------------------------
First, I took a look at the matplotlib setup.py. It had "auto" for the back-end flags, so I thought I would give it a try that way:
$python setup.py build
If you have only the static version of libpng and libfreetype (*.a, and not *.dylib) in /usr/local/lib (or anywhere else on your lib search path), then it should link those statically.
That worked!
$ sudo python setup.py install
4) And now to test!
$python
>>> import pylab
Could not open font file /Library/Fonts/NISC18030.ttf
No module named pygtk
PyGTK version 1.99.16 or greater is required to run the GTK Matplotlib backends
This turns out to be because the matlabrc file sets the GTKAgg back end as the default. You have two choices.
1) you can set the back end before importing pylab.
>>> import matplotlib
>>> matplotlib.use('Agg')
>>> import pylab
This works fine
2) Edit the matplotlibrc file. I found it in:
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/.matplotlibrc
Change the line:
backend : GTKAgg # the default backend
to
backend : Agg # the default backend
And you're all set to make images for the web, etc.
I'm going to leave getting it to work with wxPython for another day.
3) Building a matplotlib Binary Package for OS-X:
First you need to make sure you've got libpng and libfreetype staticaly linked. I did this by copying the headers and *.a files for them into a directory I created called "StaticLibs", in the main matplot lib directory (the one setup,py is in). You could just as easily put in links, rather than copies, probably a better idea, actually.
Then I edited setupext.py, so that distutils would only look there:
basedir = {
'win32' : ['win32_static',],
'linux2' : ['/usr/local', '/usr',],
'linux' : ['/usr/local', '/usr',],
# 'darwin' : ['/usr/local', '/usr', '/sw', '/usr/X11R6'],
'darwin' : ['StaticLibs'],
'freebsd4' : ['/usr/local', '/usr'],
'sunos5' : [os.getenv('MPLIB_BASE') or '/usr/local',],
}
I'm talking to John Hunter about having a conditional Static setup in the official setup.py to support this. This seemed to so the job.
To test, you can run:
$ otool -L *.so
in the matplotlib directory that is buried in the build directory. it will tell you what libs the matplotlib extensions are linked to. They should not be linked to libfreetype or libpng. libz is OK, it's included with the stock OS-X.
Once you've got that built right, you can make an installer package with Py2App.
This is a note from Bob Ippolito on the macPython mailing list:
"""use bdist_mpkg from py2app to make a redistributable .pkg installer for it. After installing py2app, you should have a tool in /usr/local/bin called "bdist_mpkg" that will Just Do It without any setup.py modifications to the target lib... so go into the matplotlib directory, type bdist_mpkg, and cross your fingers that a dist/matplotlib-xx.pkg
"""
Here's exactly what I tried:
In the matplotlib directory (the same place as setup.py)
$ bdist_mpkg
and it worked!
Note: there are occasionally troubles with installing a newer matplotlib over an older one. You may want to remove an older version before installing, if you have one. To do this, delete:
/Library/Python/2.3/matplotlib/
Then click the mpkg. to install.
Building with tcl/TK:
I downloaded the BI (Batteries Included) installer for tcl/Tk Aqua. It's got a lot of stuff I don't need, but it's only disk space. I then used the MacPython PackageManager and the standard package list, and installed Tkinter from there. It seemed to work.
Now back to the build cycle...Yeah it works!
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@...259...