Saturday, August 20, 2011

Installing libjpeg and PIL on OSX Snow Leopard with Python 2.7

If you found this article through a google search, you've probably already read through tons of articles and forums where people gave advice on how to do this. Here's some examples of what I'm talking about:


It's clearly an annoying problem, and I'm guessing none of those worked for you. While this is clearly an annoying problem and I spent at least a couple hours of head banging myself, I believe most of peoples' issues can be solved by completed a thorough cleanup. If you tried one or more of those approaches above, you probably have libjpeg and PIL folders in all sorts of places on your system that are screwing up stuff. 
To remove the libjpeg files, make sure you remove anything that looks like libjpeg* or jpeglib*. You'll also want to remove all your PIL directories. Some of the most common directories these might be living in are:

 

/usr/local/include
/usr/local/lib
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
/sw/lib
/sw/include
/opt/local/lib
/opt/local/include

Be sure to do this between trying any different installation methods or you will end up wasting a lot of time. 

 

For me, once I removed all these files, getting libjpeg and PIL to work was actually quite simple:
  1. Download this combo installer and install it with the default settings.
  2. Run "pip install pil"
I hope this helps someone!
Edit 1/7/2012: It seems that PIL is broken. Some other people revived the project by creating "Pillow", so you can just change step two above to:
pip install pillow