27
Jan
2010

Installing PIL on Mac OS X Snow Leopard for use in Google App Engine

Tags: , ,     Categories: Software

Python users who use Django or Google App Engine on the Mac, will likely benefit from the python imaging library (PIL).

However, installing on Mac OS X (Snow Leopard) can be tricky. There are many blog posts on the issue. The most common problem is that PIL and libjpeg (a dependency) seem to install OK, but when you go to use it in your Python code, you get “_jpeg_resync_to_restart” errors.

A further complication is the fact that Google App Engine uses Python version 2.5 (and not the default 2.6 that comes with Snow Leopard). If you just need PIL for Django, you can ignore the 2.5 references (i.e. python2.5 becomes python).

Here’s how I got it working on my machine (the steps are a combination of others’ blog posts, but main credit goes to Michael Richardson‘s post):

  1. Download the latest libjpeg .tar.gz (version v7 at time of writing): http://www.ijg.org/files/.
  2. Download the latest PIL version for Python 2.5 (v1.17 at time of writing): http://www.pythonware.com/products/pil/
  3. Extract libjpeg and do the standard install affair:
    export CC="gcc -arch i386"
    ./configure
    make
    sudo make install
    from within the directory. The first line is the gem that many other blog posts leave out (and it assumes you’re using BASH)
  4. Extract the PIL and change in to that directory.
  5. [optional] libjpeg will have been installed in /usr/local/lib/, by default, above. Normally this directory will be picked up automatically by the PIL install below, but just for good measure (or if you have problems later in the PIL install), edit the setup.py, look for the line
    JPEG_ROOT = None
    . Change that line to
    JPEG_ROOT=libinclude( "/usr/local" )
    and save it.
  6. Install PIL by running
    sudo python2.5 setup.py install

That was enough to get it running for me. I can start App Engine (I use the Google-provided launcher), and use the Image API.

 

4 Responses:
  1. Thijs    Tue, 16th Mar, 2010    8:08 pm   :

    Ran into this 2 days ago, this post would’ve been very helpful then :) You might want to add the version nr of libjpeg in your post because this was the issue for me; v7, or 0.7, of libjpeg introduces that ‘_jpeg_resync_to_restart’ and PIL doesn’t know how to handle it. If you simply use 0.6 of libjpeg everything’s fine (at least for me it was). But I’m not sure if that version is still distributed on that site, but anyway.


  2. Mikko Ohtamaa    Sun, 28th Mar, 2010    9:58 pm   :

    You might also find this useful: http://blog.mfabrik.com/2009/11/19/installing-python-imaging-library-pil-under-virtualenv-or-buildout/


  3. cgarvey    Sun, 28th Mar, 2010    10:13 pm   :

    Thijs, thanks for the tip, I’ve amended the version in the post. It was version 7, but I’ve not noticed the resync error you mentioned. I’ve only used basic features of PIL (cropping & resizing), so I’m not sure if that explains it.

    Mikko, thanks for the link.


  4. leandro    Thu, 27th May, 2010    7:02 pm   :

    \o/
    Tks a lot dude… simple and worked like a charm!

    hugs


 

Leave a Reply

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.