Building Matplotlib for MacOS X

These instructions are geared for building a binary installer for matplotlib on Mac OS X 10.4 that will run on 10.3.9 and later. Technically these instructions should also work on a machine running 10.5 or 10.6, but in practice I find that the resulting package cannot be used on 10.3.9 and 10.4 (I have no idea why).

If all you want to do is build matplotlib for yourself, on Mac OS X 10.6 or newer, then you need not install any extra libraries. Install XCode and the python you want to use, then jump to Install Python Packages, and skip bdist_mkpg.

Note: every line that begins with $ is intended to be typed into Terminal (without the leading $; it simply represents the Terminal's prompt).

Install python.org python

Install Python from python.org. Using this python will make your matplotlib installer maximally compatible with various versions of Mac OS X.

Install XCode (Apple's Developer Tools)

Xcode (Apple Developer Tools)

Install Xcode. If building for MacOS X 10.3.9 and later then be sure to install the 10.3 SDK. You must be a registered Apple Developer to download XCode, but registration is free.

For MacOS X 10.3.9 use gcc 4.0.1

For a version of matplotlib that runs on MacOS X 10.3.9 and later, you must use gcc 4.0.1. XCode installs several versions of gcc in /usr/bin and /usr/bin/gcc is a symlink to one of them. Fix the simlink if necessary so that it points to gcc 4.0.1.

Configure Your Environment

Install Unix Packages

Standard Installation Instructions

Unless otherwise noted, all packages are installed as follows:

When you are done installing all these unix libraries, do not forget to delete dynamic libraries (as step listed below).

libz

Install zlib (a.k.a. libz). A version is already included with MacOS X 10.4 and later, but not 10.3.9. In any case, it is probably better to provide a modern version.

libpng

Install libpng.

freetype

Install freetype. Version 2.3.12 works fine. Do not use the broken version that Apple includes with X11.

Caveats:

Remove Dynamic Libraries

To make a package the libraries you just installed must be linked in statically. Thus you must delete (or move aside) the dynamic libraries. Assuming you took my advice to create a special /usr/local for this job, the following works:

$ sudo rm /usr/local/lib/*.dylib
# verify that the remaining libraries are universal
$ file /usr/local/lib/*.a

Install Python Packages

Install numpy

Matplotlib requires numpy.

Install wxPython (Even If Already Installed!)

If you want WXAgg support you must install wxPython. I recommend the most recent stable release (2.8.x at this writing). The 2.9 series is a development branch and is best avoided unless you want to be a beta tester. Warning: if you modified /usr/local then you must install wxPython again, even if it is already installed, since wxPython puts some components in /usr/local.

Install setuptools

Install setuptools. Download it, unpack it and type:

$ python setup.py build
$ python setup.py install

Install bdist_mpkg

Install bdist_mpkg, preferably using pip or easy_install, since those will install the prerequisite packages.

Build Matplotlib

Download and Unpack Matplotlib

Configure matplotlib

Build the Matplotlib Installer

To create a double-clickable installer package that you and others can use to install matplotlib:

Run Terminal and cd to the top level of the matplotlib source directory:

$ bdist_mpkg

or you want to run a bdist_mpkg for a particular version of python you can be explicit, for example:

$ /Library/Frameworks/Python.Framework/Versions/2.6/bin/bdist_mpkg

The binary installer will be inside subdirectory dist.

Build An Egg

If you wish to have an egg distribution, you can build it as follows:

First edit setupcfg.py and comment out the two lines for pytz and dateutil so that they are not built (they should be a dependency of the egg rather than included in the egg).

Then build the egg as follows:

$ python setupegg.py bdist_egg

The egg file will be inside subdirectory dist.

Test the Result

Install matplotlib using your new installer. cd out of the matplotlib source directory and run the tests:

$ python -c "import matplotlib as m ; m.test(verbosity=1)"

Notes:

Final Cleanup

Save your /usr/local in case you wish to do future builds, and move your normal /usr/local back into place (if you had one):

$ sudo mv /usr/local /usr/local-static
$ sudo mv /usr/local-disabled /usr/local

Before distributing the binary installer I recommend a few cleanup steps:

Acknowledgements

Many thanks to Charlie Moad and mpsuzuki for help with installation instructions and to Sandro Tosi and Derek Homeier for testing instructions.

History

Russell Owen
University of Washington
PO Box 351580
Seattle, WA 98195-1580
rowen u washington edu
     @ .          .