Installing MatPlotLib on Snow Leopard with MacPorts
I have been trying to install the excellent MatPlotLib graphing module for the Python programming language on my iMac for a while now. Unlike most python module installations I’ve done the excellent python SetupTools (a.k.a easy_install) has not been up to the task. So I ended up using MacPorts (version 1.8.1) to get MatPlotLib (version 0.99.1.1) installed on Snow Leopard (OS X 10.6.2) with X-Code (3.2.1 – 1613).
So here is a brief description of how to do it:
- Install the X-Code developer tools (for GCC, make and other build tools) from your Snow Leopard installation DvD.
- Install the X11 Window System from your Snow Leopard installation DvD.
- Run ‘Software Update‘ from the apple menu on your Mac to get the latest X-Code updates.
- Download the latest MacPorts installer (.dmg file extension) for Snow Leopard from here: http://distfiles.macports.org/MacPorts/.
- Mount the installer image file (.dmg) and run the contained MacPorts installer (.pkg).
- Once installation is complete open a terminal window from Applications->Utilities->Terminal.
- Type ‘port‘ at the terminal then press enter to run MacPorts. You should see output like the following if it installed correctly:
Entering interactive mode… (“help” for help, “quit” to quit)
Then type ‘quit‘ then press enter to exit port’s interactive mode.
- Type ‘sudo port selfupdate‘ and press enter to update MacPorts to the latest version. You will be asked to enter the administrators password before continuing. Depending on how new the version you downloaded is, MacPorts may do some upgrading.
- Once the update is finished type ‘sudo port install py26-matplotlib‘ and press enter. This will attempt to install the latest version of matplotlib for Python version 2.6.*. You may be asked to enter the administrators password before continuing. MacPorts will now download, configure, build and stage the dependencies needed to build the latest matplotlib for Python 2.6. This took at least thirty minutes on my iMac and involved lots and lots of scrolling text output from the build process.
- Next we need to switch our environment to use version 2.6.* of Python that MacPorts just built and installed with matplotlib. To do this run the following two commands, note you may be asked to enter the administrators password before continuing:
- ‘sudo port install python_select‘ and hit enter.
- ‘sudo python_select python26‘ and hit enter.
- To test this all worked type the following: ‘python -V’ and hit enter. You should see output like ‘Python 2.6.4‘ which should match the version of python MacPorts built and installed.
- Finally to test if matplotlib was installed correctly do the following:
- Type ‘python‘ and hit enter to enter the python interactive shell.
- Type ‘import matplotlib‘ and hit enter, this will import the matplotlib module. There should be no output if this works.
- Type ‘print matplotlib.__version__‘ and hit enter. This will print the version of matplotlib that is installed, you should see output like ‘0.99.1.1‘.
- Type ‘exit()‘ to quit the python interactive shell.
Both comments and pings are currently closed.