MacOS X 10.7.x, Python 2.7 and PIL
Python Imaging Library (PIL) on Mac OS X Lion using Python 2.7
Here is how to build PIL. You must have the Apple Developer tools installed in order for this work. These can be found in the Apple Store under the name Xcode. Python 2.7 is bundled with OS X Lion so everybody should have it already. Download the linked requirements below and save them in your /tmp directory or copy them there manually.
If you wish to use the Finder to copy them, you'll need to press 
G to get the "Go to folder dialog". Enter /tmp to open a Finder window for that directory. For the rest of this tutorial, however, you will need to know how to use the Terminal.app to complete this tutorial.
Before we can build PIL we will need to build both libjpeg and libfreetype. We will start with libjpeg. Follow these commands. $ means the user can be any non-super user. # means that the user must be logged in as a super user or root level account.
$ cd /tmp
$ tar xzvf jpegsrc.v8d.tar.gz
$ cd jpeg-8d
$ env CFLAGS="-O -g -isysroot /Developer/SDKs/MacOSX10.7.sdk -arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" ./configure --disable-dependency-tracking
<when that completes>
$ make
<if there are no errors>
$ sudo make install
Next up we need to build libfreetype
$ cd /tmp
$ tar xzvf freetype-2.4.8.tar.gz
$ cd freetype-2.4.8
$ env CFLAGS="-O -g -isysroot /Developer/SDKs/MacOSX10.7.sdk -arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" ./configure --disable-dependency-tracking
<when that completes>
$ make
<if there are no errors>
$ sudo make install
Finally before we can build PIL. First make sure you're using the correct python.
$ which python
<should be something like '/Library/Frameworks/Python.framework/Versions/2.7/bin/python'>
If you don't see 2.7 in the output from the which command, try:
$ which python2.7
<as long as you don't see '-bash: python2.7: command not found', you'll likely be ok>
If you need to use python2.7 instead of python, please replace python with python2.7 in all places going forward. Without further ado, let's get to the final step and build PIL.
$ cd /tmp
$ tar xzvf Imaging-1.1.7.tar.gz
$ cd Imaging-1.1.7
$ env CFLAGS="-O -g -isysroot /Developer/SDKs/MacOSX10.7.sdk -arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" MACOSX_DEPLOYMENT_TARGET="10.7" ARCHFLAGS="-arch i386 -arch x86_64" python setup.py build
<when that completes and if there are no errors>
$ sudo env CFLAGS="-O -g -isysroot /Developer/SDKs/MacOSX10.7.sdk -arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" MACOSX_DEPLOYMENT_TARGET="10.7" ARCHFLAGS="-arch i386 -arch x86_64" python setup.py install
Ok, let's test to see if it's installed correctly.
$ python
Python 2.7 (r27:82508, Jul 3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>>
As long as you get another empty prompt you have successfully installed and built PIL. Enjoy using it.
Keywords: Python2.7 PIL Mac OS X Lion