In a week marred by endless work, I wanted to take a moment to recognize a small triumph. I spent several hours working on this over the last few days–and many, many hours spread out over the months before it–and finally solved the puzzle:
I managed to get Matplotlib working natively on OS X Lion.
Not a huge triumph, or even a problem that was impeding my progress. For those whose lives don’t revolve around reporting quantitative experimental results, Matplotlib is a library for the programming language Python which creates lots of pretty pictures. NumPy (Numerical Python) and SciPy (Scientific Python) are also Python libraries that extend its core functionality in ways that are useful within the scientific and academic communities (corporate as well, of course). Python is available for just about any operating system, and it comes standard on all Macs.
Problem was, upon upgrading to the latest iteration of Apple’s vaunted operating system, I discovered to my dismay that Matplotlib no longer played nicely with the other children. Try as I might, I was greeted with multiple errors: from downloading to compiling to extracting to installing to importing, and everywhere in between. Nothing seemed to work.
The internet wasn’t much help, either. Everyone seemed to be in agreement: Matplotlib on 10.7 was fundamentally broken. In order to make it work, you needed an intermediary like MacPorts or HomeBrew. While I have nothing against them–I loooooove the aptitude package manager on those wonderful Debian-based linux operating systems–I still wanted to see if there was any way at all to get Matplotlib working natively.
Say it: I’m a masochist.
I attacked this problem off and on since last fall when I initially discovered the problem, but made little progress until last night and especially this morning. As I have once again donned my TA hat this semester, and since the class makes impressive use of Python, I have students who are also facing the same issues, and didn’t want to disappoint.
So without further adieu, I present the revolutionary workflow that got Matplotlib 1.1.0 up and running on OS X.
- Install Python! Yes, this seems trivial, but here’s the catch: Apple’s prepackaged version of Python has some…issues. Without getting too technical, let’s just say it inherently won’t play nicely. Go to the Python website, find the right version of Python (mine is 2.7), and install it.
- Install setuptools. An incredibly useful utility, setuptools provides one critical component:
easy_install. We’ll use this later to actually perform the Matplotlib install.
- Install NumPy. The approach I used in steps 3 and 4 was to go to the respective downloads sections and pull down the 2.7 version of the .dmg installers for 10.6 (yes, 10.6: as of this writing, that is the latest version available). You could probably use
easy_installhere as well, but I did not test that route.
- Install SciPy. Again, I picked up the .dmg installer for Python 2.7 built for 10.6 and up.
- Install pkg-config. A bizarre dependency that seemed to be the lynchpin of the entire operation. Furthermore, the latest version as of this post–0.26–didn’t even work! I went down one version to 0.25, did the usual Unix-style “./configure ; make ; make install” process, and everything was hunky-dory.
- Install libpng. Another interesting caveat: Apple has a prepackaged version of this, but the Matplotlib installer doesn’t see it. I had to go here to get the libpng installer.
- Finally, install Matplotlib. I did a simple “
easy_install matplotlib” and that seemed to do the trick. Pay close attention to the status screen that pops up after it downloads the package: that tells you what dependencies you have that it can find, what dependencies you have that it can’t find (FreeType may fall in this category, so watch carefully if the build fails), and what dependencies you don’t have at all. It’s also possible you may be able to use the .dmg installer from the Matplotlib website instead of
easy_install; again, I did not test that route.
It was quite a ringamarole, a far cry from 10.6 and below when I simply downloaded the Matplotlib .dmg installer and poof, it was up and running. But it works! Chalk all those hours up to…something useful! Or just something!
::UPDATE:: It looks as though, as of Feb 15, Matplotlib has issued an update marked “10.6” which, more than likely, fixes all the above steps and returns matplotlib to a one-package install. So! Ignore this entire post, and happy Matplotlib-ing! 😛