Python Imaging Library: easy_install or makes a difference

Chances are most readers of the Plucked Chicken will have no idea what I’m writing about here. That’s OK. Just move along.

For anyone who may find this post when searching for Plone and an Import Error, when it claims that the Python Imaging Library is not installed because it can’t import PIL, read on.

I’m just now getting a handle on installing Plone via zc.buildout, with a view toward a migration path from a current install on a somewhat critical web site to the next great thing (TM). I decided to install a custom Python in a custom location, so that zc.buildout and easy_install would be able to do their thing without messing up my system Python installations. So far so good.

The problem came after easy_installing PIL (which isn’t as easy as one might hope), running buildout, and starting Plone. Plone complained that it couldn’t import PIL, implying that PIL was not installed. I first made sure that the Zope instance was running the correct Python install, and then I was baffled. I could verify that PIL was installed by a successful “import Image” in the Python shell, but Plone does not import Image directly. Instead, it imports PIL, or perhaps imports through PIL, as “from PIL import Image”.

Two different ways to import PIL, giving access to the same code. Two different ways to install PIL, with the “easy” one being a little more complex than usual. Putting two and two together, I removed my PIL installation, downloaded a tarball, and ran “python install”, which uses setuptools without easy_install. Everything worked smoothly. I started a Python shell and tried “import PIL” (which hadn’t worked before). This time it worked. Tried starting the Zope instance. It worked too.

Conclusion: Python Imaging Library and easy_install don’t work together the way PIL and setuptools do, resulting in two different ways to import the PIL code. This may be a PIL bug, or it may be that the egg-creation mechanism in easy_install doesn’t handle the requirements of PIL as it should. Either way, if you intend to use PIL with Plone, you’ll have to install it via setuptools. If there’s a better way, I’d appreciate hearing about it.

One thought on “Python Imaging Library: easy_install or makes a difference

  1. Thanks for the post. I had a hell of a time getting PIL to work on my windows box here. I had to do the following to get it to work on my machine:
    1. Completely uninstall any previous attempt at PIL.
    2. Download the tarball like you said and run the setup install script: “python install”
    3. Find out that it errors out during setup because of some stupid cygwin tk84.dll.
    4. Open a shell and cd to cygwinbin.
    5. >ash
    6. $.rebase -b 0x1000000000 tk84.dll
    7. $exit
    8. Now retry the setup install script.
    9. Open up a python command line and type: “import Image”
    10. Find out that this errors out as well.
    11. Start pulling out what little hair I have left… Then notice that this installed PIL under my cygwin’s usrlibpython2.5site-packages folder and not under my windows C:Python2.5Libsite-packages folder.
    12. Decide I have nothing left to lose and run the windows installer “PIL-1.1.6.win32-py2.5.exe”.
    13. Deep breath, cross my fingers and open another freaking python command line and type “import Image”.
    14. Honestly, I can’t believe it took all of that to get this to work!!! FU PIL!

Leave a Reply