Yesterday, while preparing for AgileIndia 2012 and my talk there, I wanted to get graphite installed and running on my MacBook Pro. This ended up costing me an evening of yak shaving…

In theory, this should be easy. Just install the necessary python packages, setup graphite and its components (whisper database and carbon I/O-server), start a web server and – presto!, off you go.

With one exception – pycairo - all of graphites dependencies can be installed using pip (or easy_install). Pycairo, on the other hand, turned out to be another story completely. Pycairo is a package of python bindings for the cairo graphics library and is used by graphite to produce the graphs that we (well at least I) have come to love.

Zeroth problem: pycairo depends on cairo which is best installed using homebrew.

First problem: pycairo cannot be installed using pip (writing this I am unsure whether I tried easy_install at all). Something about a missing setup.py file. Ok, guess I could install it from a source download then…

Second problem: Installing pycairo from source (tar-ball) is not possible because of some kind of incompatibility with Python 2.6.1 (default installation on  OSX Snow Leopard) and perhaps some kind of cross compilation issue for x86_64 cores (sigh).

Third problem: Ugrading the (default) python installation (especially beyond 2.6) on OSX may confuse yourself or parts of your system (that depend on Apples installation of python). See for example the homebrew documentation for its python 2.7 formula.

A hero emerges

Having spent the better part of my evening getting this far I was about to give up. Then it dawned on me – why am I spending all this time trying to upgrade my default python installation when I should be using virtualenv?

Indeed, with python 2.7.1 installed via homebrew (but not overriding Apples default installation) I could get a python 2.7 virtual environment up and running. In the new python 2.7 environment I could perform the pycairo installation from source with a few tweaks (see below). After that, moving on with the final installation steps for graphite (still inside the virtual environment) was a breeze.

So, next time I hope I will remember setting up a virtual environment sooner.

I would never have realized what I was missing or doing wrong if it had not been for these posts:

  1. http://eternusuk.blogspot.com/2011/09/installing-graphite-on-osx-snow-leopard.html
  2. http://stackoverflow.com/questions/6886578/how-to-install-pycairo-1-10-on-mac-osx-with-default-python 
  3. http://www.niconomicon.net/blog/2011/10/09/2120.wrestling.python.snow.leopard
In the process I also discovered virtualenvwrapper. It simplifies managing virtual environments and helps you stay disciplined while doing so.
About these ads