Tuesday, September 18, 2012

Installing PIL on OS X Mountain Lion

Installing PIL, the Python Imaging Library, on OS X sometimes gives problems with missing JPEG support. I have run into this problem before but could not find my solution so I'm adding it here as a note to self with "PIL" and "install" tags so I can locate the trick again in the future.
Here's the procedure.

1. Get libjpeg from http://www.ijg.org/files/jpegsrc.v8c.tar.gz. Then in the unpacked folder:
./configure
make
sudo make install

2. Download PIL from http://effbot.org/downloads/Imaging-1.1.7.tar.gz. (Remove PIL first if installed already.)

3. In the unpacked folder:
python setup.py build --force
sudo python setup.py install
The magic part for me was "--force". Without it it doesn't work. If you still don't get "JPEG support available" in the console when you run the first build command, then you can try adding the path to libjpeg in setup.py (basically just replace the "None" with your path). For example like this:
JPEG_ROOT = "usr/local/lib"

6 comments:

  1. I got mine working using the Homebrew version of libjpeg 8 (brew install libjpeg), then installed PIL 1.7.1 with pip under Python 2.7.

    ReplyDelete
  2. You should take a look at Pillow as well (http://pypi.python.org/pypi/Pillow/). It's a fork of PIL that has had updates not long ago, I know that it helped me solve issues when trying to build under a virtualenv where I couldn't get PIL to buidl.

    ReplyDelete
  3. This worked for me:

    - Install XCode
    - Install XCode's command_tools
    - sudo easy_install pip
    - sudo pip install PIL

    Thanks to Arthur Wiebe...

    ReplyDelete
  4. Also, you can avoid the painful process of having to compile things by using a pre-packaged Python such as the Enthought Distribution. It's free, with Python 2.7.2, PIL, numpy & SciPy packaged together: http://www.enthought.com/products/epd.php

    ReplyDelete