Image troubleshooting


Problems with imaging libraries, image loading and image scaling.

How to test see if your Python Imaging set-up works

Example how to check if Python, Python Imaging Library (PIL) and libjpeg are correctly working together.

Get a sample image:


Start Python with Zope libraries in PYTHONPATH or Plone debug shell (latter):


# bin/instance debug  # <--- needs Plone site stopped first

Run the following on the interactive Python prompt started above:

import PIL
from PIL import Image
im ="JohnCarrollGilbertStuart.jpg")  # Open downloaded image
im.thumbnail((64, 64), Image.ANTIALIAS)  # See that PIL resize works"test.jpg")  # See that PIL JPEG writing works

No Python exceptions should be risen.

Images are not loading

Plone is not loading images or resized images are not available is usually caused by broken PIL installation: PIL used by Python virtual machine driving Plone does not have proper native libraries (libjpeg) available to perform imaging operations.

If you run Zope on foreground you usually see errors like this:

2009-10-22T17:31:04 ERROR Archetypes None
Traceback (most recent call last):
  File "/home/xxx/xxx/parts/plone/Archetypes/", line 2333, in createScales
    imgdata, format = self.scale(data, w, h)
  File "/home/xxx/xxx/parts/plone/Archetypes/", line 2382, in scale
    image.thumbnail(size, self.pil_resize_algo)
  File "/usr/lib/python2.5/site-packages/PIL/", line 1523, in thumbnail
  File "/usr/lib/python2.5/site-packages/PIL/", line 155, in load
  File "/usr/lib/python2.5/site-packages/PIL/", line 223, in load_prepare =, self.size)
  File "/usr/lib/python2.5/site-packages/PIL/", line 36, in __getattr__
    raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed

In the above case PYTHONPATH incorrectly tries to load Python 2.5 libraries, though Plone 3.x exclusively uses Python 2.4. In this case the proper fix is to clean-up damaged start up scripts in bin/ folder:

xxx@xxx:~/xxx/bin$ grep -Ri "python2.5" *
buildout:  '/usr/lib/python2.5/site-packages',
instance:  '/usr/lib/python2.5/site-packages',
zopepy:  '/usr/lib/python2.5/site-packages',

This can be achieved by

  • Removed all py2.5 eggs under eggs/ folder
  • Removing setuptools egg which may contain references to Python 2.5
  • Running using python2.4
  • Rerunning buildout after this

For further debugging the problem you can start the particular Python interpreter and try to import _imaging yourself.

Run Python in verbose mode to print all imports (the example below has been shortened):

(python-2.4)moo@murskaamo:~/isleofback$ python -v
Python 2.4.6 (#1, Jul 16 2010, 10:31:46)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: cannot open shared object file: No such file or directory
>>> exit

In this case we have a custom Python build based on collective.buildout.python recipe. It will compile us a custom libjpeg version and should not use OS libjpeg:

(python-2.4)moo@murskaamo:~/code/python$ find . -iname libjpeg*

However, looks like this libjpeg does not end up in the OS LD_LIBRARY_PATH import list automatically.

For more information see

IOError when scaling images on Plone 4


Traceback (most recent call last):
  File "/srv/plone/xxx/plone-new/eggs/", line 73, in createScale
    imgdata, format = field.scale(data, width, height)
  File "/srv/plone/xxx/plone-new/eggs/Products.Archetypes-1.6.6-py2.6.egg/Products/Archetypes/", line 2501, in scale, format, quality=self.pil_quality)
  File "/srv/plone/python/python-2.6/lib/python2.6/site-packages/PIL-1.1.6-py2.6-linux-x86_64.egg/PIL/", line 1372, in save
  File "/srv/plone/python/python-2.6/lib/python2.6/site-packages/PIL-1.1.6-py2.6-linux-x86_64.egg/PIL/", line 207, in load
    raise IOError(error + " when reading image file")
IOError: decoding error when reading image file

This means that libjpeg setup is not working. See above to how to test your set-up.

Installing libraries on Ubuntu / Debian

This applies if you are using system Python to run Plone. Version may vary so apt-cache search and grep commands are your friends:

sudo apt-get install libpng12-dev  libjpeg62-dev python-imaging

Forcing libjpeg path

Try in buildout.cfg:

environment-vars =
        LD_LIBRARY_PATH /srv/plone/python/python-2.6/lib