How to Install Python’s Matplotlib on Mac OS X Lion

|

Argh. I just want to plot some charts in Python. Why does it have to be so hard?

I tried to

easy_install matplotlib

but this fails with some byzantine errors that I can’t make heads or tails with.

So after going through the tedious process of figuring out what’s wrong when a package installation fails (here, here, a here), I finally found a page that promised to take me to the land of milk and honey.

But my journey wasn’t over. OS Lion choked on

python setup.py build

So then I found this very detailed page on how to install Python, NumPy, SciPy, matplotlib and IPython on Lion.

Everything’s going well for a bit as I follow each step in order. And I get stuck on

pip install -e git https://github.com/scipy/scipy#egg=scipy-dev

with error “no matches found”. I looked around on the github repo for a tag with egg=scipy-dev but couldn’t find anything.

But I figured it out! Just build from source. This is always a last resort for me, because package managers make it so easy to install and uninstall. I’m often scared of building from source because I see a flood of matrix green letters cascading down my black background terminal. And I have no idea what’s going on. But this seems to be the only way for now until the packages are fixed.

git clone https://github.com/matplotlib/matplotlib
cd matplotlib
python setup.py build
python setup.py install

To check your installation:

1
2
3
import matplotlib
print matplotlib.__version__
print matplotlib.__file__

You should see version 1.1.0 (as of this writing) and path /usr/local/Cellar/...

To Install Scipy

git clone https://github.com/scipy/scipy
cd scipy
python setup.py build
python setup.py install
1
2
3
4
python
import scipy
print scipy.__version__
print scipy.__file__

You should see version 0.10.0 dev (as of this writing) and path /usr/local/Cellar/...