Matplotlib + Lion = Matplionlib?

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.

  1. 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.
  2. Install setuptools. An incredibly useful utility, setuptools provides one critical component: easy_install. We’ll use this later to actually perform the Matplotlib install.
  3. 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_install here as well, but I did not test that route.
  4. Install SciPy. Again, I picked up the .dmg installer for Python 2.7 built for 10.6 and up.
  5. 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.
  6. 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.
  7. 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! 😛


About Shannon Quinn

Oh hai!
This entry was posted in Academics, Graduate School, Internet, lolcat, Programming, Technology, Tutorial and tagged , , , , , , , , , , , , . Bookmark the permalink.

3 Responses to Matplotlib + Lion = Matplionlib?

  1. eksith says:

    “Not a huge triumph.”

    At the end of Lord of the Rings : Return of the King, Frodo, Sam, Pippin and Merry are at the pub AFTER HAVING FOUGHT THE IN THE GREATEST BATTLE OF THEIR LIVES. The rest of the hobbits are carrying on in their own world laughing and telling their own small stories without a care, and the four friends smile to each other in acknowledgement of their own triumphant story and have a beer.

    Sometimes it’s the quiet reflection on personal victory over an ordeal few others have known that’s the most meaningful. Still worth a glass o’beer.

    • magsol says:

      This is pretty much the story of graduate school: small victories that hopefully, eventually, build on themselves into publications and a degree. It was a problem that, while not a show-stopper, was quite an annoying inconvenience, and it was very relieving to finally find a fix.

      Come to Pittsburgh sometime, and we’ll have that beer! 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s