70

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?

4 Answers 4

95

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.

16
  • Is the author being notified about this, so that it gets fixed on pypi, too?
    – blueyed
    Mar 29, 2010 at 23:20
  • 1
    I tried the version shown in your example but I still had the same problem. I ended up using the installer from the pythonware website, then copied the PIL directory and PIL.pth file to the virtualenv, and it solved the problem for me.
    – tponthieux
    Feb 7, 2011 at 6:45
  • 14
    Pillow is a fork of PIL made with the goal of fixing the packaging, it seems to be a drop-in replacement.
    – tvon
    Mar 11, 2011 at 17:19
  • 1
    Solved the problem for me. Just make sure you remove the broken PIL first. Jun 14, 2011 at 17:16
  • 4
    @MartijnPieters And six months later that change has still not been released, which is a pretty good reason to support the fork IMHO. Further, Pillow basically accomplishes the same thing as the accepted answer above, without having to specify the alternate index.
    – aclark
    Oct 14, 2011 at 16:09
79

Use Pillow: the "friendly" PIL fork :-) It offers:

  • Full setuptools compatibility
  • Faster release cycle
  • No image code changes that differ from PIL (i.e. it aims to track all PIL image code changes, and make none of its own changes without reporting them upstream.)
  • Windows binaries

If PIL ever does exactly what Pillow does, then the fork will die. Until that happens, we have Pillow.

DISCLAIMER: I am the fork author, and Pillow was created mainly to make my job easier (although it's great to see other folks using it too).

EDIT: Pillow 2.0.0 was released on March 15, 2013. It offers Python 3 support and many bug fixes/enhancements. While we still attempt to track changes with upstream PIL, (unfortunately or fortunately depending on how you look at it) Pillow has begun to drift away from PIL.

6
  • Thank you for your work! I also tried to get my pyramid buildout working with PIL but now I discovered this discussion and I replaced it with Pillow and it worked. :-) Jan 8, 2012 at 18:30
  • 1
    Thanks for Pillow @aclark ! After at least a year of struggling with PIL everytime I build new machines and always having problems with JPEG and PNG support on Ubuntu with virtualenv, buildout and setuptools, I found Pillow! Now, just a setuptools definition and it just works. A thousand thanks! Jun 6, 2012 at 22:18
  • I don't think this is necessary anymore though -- it works with setup tools now right? Jul 24, 2012 at 22:09
  • @Ranman That depends on what you mean by "works with setuptools". There hasn't been a new PIL release since the fork was made in 2010, if that helps.
    – aclark
    Jul 26, 2012 at 0:14
  • The standard way of accessing the Image module is to from PIL import Image. But in PIL there was also import Image, and in many places I find just that. I have Pillow 3.0.0 on Windows and it doesn't support bare import Image. How to solve it without hacking the dependent code? Jan 15, 2016 at 10:56
8

For Ubuntu I found I needed to to install the C headers package for my python version (2.7)

sudo apt-get install python2.7-dev

Afterwards, pip install pil worked.

1
  • I also needed the Python.h file while trying to install PIL in an Ubuntu virtualenv, this fixed it!
    – Deep-B
    Feb 20, 2014 at 23:09
6

On Windows, I installed PIL in a virtualenv as follows:

Install PIL in your global python site-packages by executing the .exe from: http://www.pythonware.com/products/pil/

Then, as a "do it yourself-er", copy the PIL.pth file and PIL directory in C:\Python25\Lib\site-packages to your virtualenv site-packages directory. Yeah, python is still a "get your hands dirty" environment...

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.