
Pythonware’s PIL, the Python Imaging Library, is an extension to Python enabling you to process and arrange images quickly. It supports the popular JPEG and PNG image formats and provides font rendering using the freetype2 library. Unfortunately, PIL is not included in the standard Python environment on Mac OS X 10.4/10.5, so you have to download and build it.
First of all, you might find that there is plenty of forum/blog posts, articles etc. on the web attempting to provide useful instructions on how to build and install PIL in the right fashion. However, I found that most of them are telling different things and so I didn’t really trust them. I tried a lot and basically all of them failed. I am going to explain now, why that was.
Following the README what you need in advance is: libjpeg (6b), libpng3 and freetype2. You can get these using fink or MacPorts. Since I don’t like my machine to re-compile all the stuff that is easily available in a binary form, I used fink.
After installing the required libraries via fink I tried to build PIL using the command as described in the README file:
$ python setup.py install
… and all I got was a lousy:
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 supported not available
It turned out that the setup.py file did for some reason not search the correct directories for the freetype2 library. Fixing this is quite easy: just set
FREETYPE_ROOT = "/sw/lib/freetype2/lib"
Note: This does only apply as long as you use fink. MacPorts directories differ!
I again built PIL using the setup.py install command. Everything seemed OK this time. So, as suggested by the installer script, I tried to run PIL’s self test now using
python selftest.py
which would result in
Failure in example: _info(Image.open("Images/lena.jpg"))
from line #24 of selftest.testimage
Exception raised:
Traceback (most recent call last):
File "./doctest.py", line 499, in _run_examples_inner
exec compile(source, "
I googled and googled and found a lot of similar results, but no answers unfortunately. After some time I realized that PIL would run from any other directory, but only the selftest.py failed. The reason for this is that in the Imaging-1.1.6 directory there is a PIL.pth file and a PIL subdirectory. Python picks these up and tries to run PIL from there. Of course this cannot succeed, since the library is not built properly for our system there. The solution is to delete both the PIL subdirectory and the PIL.pth file and there it goes – the self test runs through without any failures.
Hope I have saved you some valuable time.





5 responses so far ↓
1 desertrat Feb 18, 2009 at 9:21 pm
I wish I’d found your post 3 days ago. Would have kept that head-shaped dent out of my desk.
2 Roland Frédéric Feb 23, 2009 at 1:50 am
Thank you for this post, it helped me a little bit toward installing PIL on Mac OS X. Unfortunatelly I was never able to complete Freetype2 installation using fink. I had to install it from source.
3 Thanker Jul 25, 2009 at 2:51 am
exactly. Delete the PIL folder in the src folder is great
thumbs up…
4 Phil Aug 6, 2009 at 9:47 pm
thank you for this!
5 Bruce Oct 7, 2009 at 8:58 pm
I love you cuz I was getting really pissed at this.
Leave a Comment