May 16, 2010

Matplotlib, NumPy and SciPy for Python 2.6 on MacOS 10.6 - the hard way

Prerequisites: have Macports and Python 2.6 installed on MacOS 10.6 (for 10.5 users, please note the side note at the bottom of this post) as explained e.g. in this blog post.

To get SciPy running with matplotlib etc, run the following commands in a shell, taken and adapted from here (kudos to the autor and the commentators).
Be aware, that installing all these packages might take a lot of time, so bring with you some patience and a good cup of tea and don't worry, if there is nothing happening for quite a while on the console.
sudo port install py26-numpy
this takes quite a while if you have not already installed the gcc 4.3 (on Polyhymnia just this took me more than one hour)...
sudo port install py26-matplotlib +qt4
wxpython is broken right now for Snow Leopard (MacOS 10.6), therefore you need to use another alternative backend, which you can specify via +qt4 in this case. However, compiling and installing py26-matplotlib including qt4 took a significant amount of time, in my case roughly 3 hours. After successful install you get the following answer:
The default backend is now the non-interactive Agg backend, different
backends can be specified using the ~/.matplotlib/matplotlibrc file.
Then install py26-scipy and iPython
sudo port install py26-scipy
sudo port install py26-ipython
py26-scipy took roughly 15 minutes to compile. iPython is an interactive shell for matplotlib, drop it in the line above if you don't want to use it.

Finally, you need to create the file ~/.matplotlib/matplotlibrc and specify the backend for matplot lib by adding (or editing, if the file already exists) the line:
backend : Qt4Agg  # Use gt4 as the plotting backend
otherwise you will not be able to see any drawing output of matplotlib. Regarding the backend, you might want to read this.
Now you should be able to use the packages.

Side note: For users with MacOS 10.5 - Leopard, you can choose to install
py26-wxpython (sudo port install py26-wxpython) as backend. In this case, please install first py26-wxpython and then py-matplotlib without "+qt4" and create/edit the file ~/.matplotlib/matplotlibrc
to
backend : WXAgg # Use wxpython as the plotting backend.

No comments: