Sunday, December 14, 2008

Pylons & PIL (Python Image Library)

Pylons is moving along nicely and I am delighted by that fact. The Pylons book was recently sent for publishing. Pylons itself reached the final RC versions. Christmas is coming. What more could one want. Fine maybe not everything is going that smooth but at least we can pretend.

Without further general talk the topic for today: Pylons and PIL in a virtualenv.

I am on an Ubuntu machine with the latest updates installed. Recently I started a new project with Pylons using the latest version (as of time of writing it is 0.9.7rc4). I setup a virtualenv and began tapping the keyboard. Soon enough I needed to manipulate some images and what better way to do it then PIL. Let the tough stuff begin.

Ubuntu comes with python-imaging package which is exactly PIL but the way it is packaged it does not get picked up by while virtualenv is being created. I poked around the directory structure where PIL is installed and found it to be linked to another directory (/usr/shared/pyshared I think it was). I guess the Ubuntu guys who rely on python extensively need the library and for convenience or something else distribute the package like this. So system-wide PIL is out of the question. Need to install on in the virtualenv then.

Downloaded the source and upon attempting to build the package a whole twenty something screen of errors poured. This missing, that missing... Holy cow! Scrolled way back to the beginning and noted that Python.h was missing. A-ha! Quick fix:

sudo apt-get install python-dev

Presto! Compilation wend on like a charm. Time for selftest.py. Bang! No-go again. One test of 57 failed:

IOError: decoder jpeg not available
1 items had failures:
1 of 57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.

Searching here and there the "cure" was found:

sudo apt-get install libfreetype6-dev libfreetype6 libjpeg62-dev libjpeg62

After a recompile and a selftest.py again everything looks fine:

57 tests passed.

The obligatory check in the virtualenv was in order:

$ python
Python 2.5.3a0 (r252:60911, Nov 23 2008, 12:10:42)
[GCC 4.3.3 20081122 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>>

Works like a charm. Time to get on cracking on the source again. Hope this helps someone!

No comments: