Building PIL on OS X: Snow Leopard

Published on Feb. 25, 2010, 9:40 a.m.

homebrew mac os pil python virtualenv x

There are several places online that discuss problems installing PIL on Mac OS X Snow Leopard

This is how I got it to work.

  1. Install lib jpeg using homebrew (which is super-aweseome!)
    brew intall jpeg
    .This installs the library into
    /usr/local/Cellar/jpeg/7

  2. Install libfreetype the old-fashioned way (./configure, make, sudo make install). I used freetype-2.1.10.pre-20050511.

  3. Download, unpack PIL (I used Imaging-1.1.6). I had to make the following changes to setup.py
    FREETYPE_ROOT = "/usr/local"
    JPEG_ROOT = ("/usr/local/Cellar/jpeg/7/lib", "/usr/local/Cellar/jpeg/7/include")

  4. Then, build PIL:
    python setup.py build_ext -i

  5. If the build works without any errors, you can run the tests:
    python selftest.py
    which should yield the following: 57 tests passed.

  6. (optional) I like to use virtualenv, so I activate that:
    workon myproject

  7. Install PIL:
    python setup.py install

At this point, code like the following works for me:
import Image
im = Image.open("/path/to/pretty/picture.jpg")
im.show()
comments powered by Disqus