Building PIL for OS X 10.6 – The Right Way
September 12th, 2010

Per my previous post, it may be apparent that I’m working on a just-for-fun Django project that uses the Python Image Library (PIL).  Overall, it’s pretty easy to set up, but the instructions I found on the internet were just wrong enough to make me have to dig around for 20 minutes getting it to work.

Disclaimer: The above instructions *might* work for you, so feel free to try them first.

Anyway the issue I was having: After installing PIL through the above instructions, I tried to upload an ImageField file through the Django Admin interface.  I’d get the following error:

The _imaging C module is not installed

Some quick google-fu led me to this page which explained that Python probably could not find the _imaging module, or else that module wasn’t being loaded correctly.   This was strange because I had just installed PIL, and PIL showed up in my sys.path.  However, running:

>>> import _imaging

Showed the following message:

ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/_imaging.so, 2): no suitable image found.  Did find:
/Library/Python/2.6/site-packages/PIL/_imaging.so: mach-o, but wrong architecture

Ah-ha!  The original instructions indicated that it was required to change the build flags for a 64 bit architecture, but for me that was not necessary and in fact build incompatible binaries for my system.

For those following along, the correct instructions for my system were as follows:

$ curl -O http://effbot.org/downloads/Imaging-1.1.6.tar.gz
$ tar zxf Imaging-1.1.6.tar.gz
$ sudo bash
# cd Imaging-1.1.6
# python setup.py build
# python setup.py install
# exit
Installing Python Image Library (PIL) on Webfaction for Python2.6 / Django
September 9th, 2010

Webfaction is a pretty decent “set it and forget it” webhost, which I’ve been using for a number of years.  One thing I’ve noticed lately is that they’re not totally consistent with which software versions among servers, or at least based on some of the forum threads of theirs I’ve read.  Long story short, python2.5 and lower come with PIL, but for whatever reason, python2.6 doesn’t have it.  To get it going, do the following:

cd /home/<your_username>/lib
mkdir python2.6
easy_install-2.6 http://dist.plone.org/thirdparty/PILwoTk-1.1.6.4.tar.gz

That’s pretty-much it.  For some reason the python2.6 dir doesn’t exist, but you can add it back and easy_install whatever libs you need.