Building Matplotlib for MacOS X

Here are instructions for building a universal version of matplotlib for MacOS X 10.3.9 and 10.4 from source, including building an optional binary installer. Much thanks to Charlie Moad and mpsuzuki for help.

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

Install Prerequisites Unix Libraries

First install the prerequisites.

Xcode (Apple Developer Tools)

Install Xcode, including the 10.4 SDK (which is part of the default installation for recent versions).

libz

A universal zlib (a.k.a. libz) is included with MacOS X 10.3.9 and 10.4. If you ever installed a copy yourself, get rid of it or make sure it's universal.

libpng

Install libpng. Download and unpack anywhere convenient. Then (using Terminal) cd into the unpacked directory.

freetype

Install freetype. Version 2.1.10 works fine. Do not use version 2.2.1 because it is broken on MacOS X (but the next release should be fine). Do not use the broken version that Apple includes with X11.

Get source, unpack, and install exactly as for libpng (above) except:

Install Python

Install a universal version of Python (the one built into MacOS X 10.3.9 or 10.4 will not do). MacOS X binary installers are available from http://www.python.org/ftp/python.

If using Python 2.4, you must fix it to be compatible with user-installed versions of Tcl/Tk (Python 2.5 does not need fixing). If you omit this step then your matplotlib will simply crash on many people's machines. The fix is easy: run fixtkinter, a short python script that makes a simple modification to _tkinter.so. The header of the script explains what it's doing.

Install numpy

Matplotlib requires numpy. (As of this writing matplotlib can also use numarray or Numeric, but that will soon change). Look for binary installers from macpython.org/packages/ or install from source using the usual sequence:

% python setup.py build
% sudo python setup.py install

Install wxPython (Optional)

If you want WXAgg support you must install wxPython. Binary installers are available from macpython.org/packages/. 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.

Note: if you must use wxPython 2.7.x or older you will get better performance if you set environment variable WX_CONFIG to the path to the correct wx-config (you can find this path by executing "find /usr/local/lib -name wx-config"). Do not bother for wxPython 2.8.x or newer.

Configure Matplotlib

Go to the top level of the matplotlib source directory. Copy setup.cfg.template to setup.cfg, then edit setup.cfg to set the desired default backend. If setup.cfg.template does not exist then edit matplotlibrc.template instead and replace %(backend)s with the actual desired backend. If you plan to release a binary installer, I strongly recommend using TkAgg as the default back end so users can run it out of the box.

If you skip this step then matplotlib will pick valid values, but they may not be your desired defaults. You can (and probably should) override the defaults by creating your own ~/.matplotlib/matplotlibrc file in any case (preferably only containing the few lines you care about, so it will be compatible with future versions of matplotlib).

Build and Install Matplotlib

Note: if you are making a binary installer (see next step) then I suggest you skip this step and use the installer you create, instead.

Build and install matplotlib in the usual fashion:

% python setup.py build
% sudo python setup.py install

Make a Binary Installer (optional)

To make a double-clickable installer package that you or others can use to easily install matplotlib:

Install bdist_mpkg, e.g. using easy_install.

Edit matplotlibrc.template in the top level of the matplotlib source directory, setting backend and numerix to your preferred values. If you plan to release a binary installer, I strongly recommend using TkAgg as the default back end so users can run it out of the box.

Create the installer using bdist_mpkg (run this from the root directory of your matplotlib distribution):

% bdist_mpkg

The resulting binary installer will be inside subdirectory dist.

Make sure your users also have binary installers for pytz, dateutil and a suitable numeric package. These can be obtained from http://pythonmac.org/packages/.

Note: if bdist_mpkg does not work, then /Library/Frameworks/Python/Versions/Current/bin is probably not on your path. Either put it on your path (highly recommended) or call bdist_mpkg using the path just mentioned.

History

2007-12-04. Updated configuration forsetup.cfg.template (new in matplotlib 0.91).

2007-11-28. Updated wxPython section for wxPython 2.8.x, which does not need environment variable WX_CONFIG set. Also noted that matplotlib will soon only use numpy.

2006-12-12. The section on installing MacPython now suggests patching only Python 2.4 (Python 2.5 does not need it). Various edits for clarity.

2006-12-11. Added Xcode section at the suggestion of Markus Rosenstihl.

2006-11-14. Amended "Make a Binary Installer" to discuss modifying setup.py to include dateutil, pytz and numeric packages.

2006-11-09. Added wx installation instructions. Much thanks to Christopher Barker for the information!

2006-10-30. First html version (adapted from a netnews posting)

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