The problem with installing PIL using virtualenv or buildout

Alexander Artemenko picture Alexander Artemenko · Mar 21, 2010 · Viewed 41.8k times · Source

When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'.

However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.

Here are examples of how I trying to install PIL using virtualenv:

# virtualenv --no-site-packages test_pil
# test_pil/bin/easy_install PIL
# test_pil/bin/python
Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL

I see, that easy_install pack PIL into the Egg, and PIP does not. Same thing with buildbot, it uses eggs.

How could I install PIL properly, using easy_install or buildout?

Answer

Martijn Pieters picture Martijn Pieters · Mar 21, 2010

The PIL version packaged on pypi (by the author) is incompatible with setuptools and thus not easy_installable. People have created easy_installable versions elsewhere. Currently, you need to specify a find-links URL and use pip get a good package:

pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

By using pip install with the --no-index you avoid running the risk of finding the PyPI (non-fixed) original of PIL. If you were to use easy_install, you must use a direct link to the source tarball of a corrected version; easy_install stubbornly still uses the PyPI link over the find-links URL:

easy_install http://dist.plone.org/thirdparty/PIL-1.1.7.tar.gz

To include PIL in a buildout, either specify the egg with the same version pin or use a versions section:

[buildout]
parts =
find-links =
    http://dist.plone.org/thirdparty/
eggs =
    PIL
versions = versions

[versions]
PIL = 1.1.7

Edit March 2011: Fixes to address the packaging issues have been merged into PIL's development tree now, so this workaround may soon be obsolete.

Edit February 2013: Just use Pillow and be done with it. :-) Clearly waiting for the original package to be fixed has not paid off.