Installing PIL on Mac OS X

From Akvo Labs

Jump to: navigation, search

Preamble

Akvo RSR requires that the Python Imaging Library (PIL) be installed on your system.

Whilst PIL is trivial to install on Linux systems, most of us use Mac OS X for daily development work. PIL is a bit more difficult to get running on OS X and, because of this, isn't a candidate for pip/virtualenv setups.

This document aims to provide guidelines for getting PIL up and running on your Mac.

You must have the Xcode development tools installed on your system before proceeding. Technically only the Unix Development component package of Xcode is required.

Installation

PIL depends on zlib for PNG support, libjpeg for JPEG support and the freetype library. Only headers and includes for zlib are included in the Xcode package so the other two have to be downloaded.

Download the latest releases of PIL, libjpeg and freetype:

Unpack all of these into a working directory somewhere, for example /tmp:

 $ cd /tmp 
 $ tar xzvf /Users/paul/Downloads/freetype-2.3.9.tgz

The below examples are based on the latest releases available at the time of writing.

Compile and install freetype:

 $ cd /tmp/freetype-2.3.9
 $ ./configure
 $ sudo make install

Compile and install libjpeg:

 $ cd /tmp/jpeg-7
 $ ./configure
 $ sudo make install

Unless you specify otherwise (probably a bad idea), both these libraries will be installed into /usr/local.

Install PIL:

 $ cd /tmp/Imaging-1.1.6
 $ sudo python setup.py install

Finally, check that you can import PIL in the python command interpreter:

 $ python
 >>> from PIL import Image
 >>>

If you get an ImportError, then something has gone wrong. A blank >>> prompt indicates success.

Personal tools