(画像に関する問題)

画像が読み込まれない

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/Field.py", line 2333, in createScales
    imgdata, format = self.scale(data, w, h)
  File "/home/xxx/xxx/parts/plone/Archetypes/Field.py", line 2382, in scale
    image.thumbnail(size, self.pil_resize_algo)
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1523, in thumbnail
    self.load()
  File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 155, in load
    self.load_prepare()
  File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 223, in load_prepare
    self.im = Image.core.new(self.mode, self.size)
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", 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 bootstrap.py 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: libjpeg.so.8: 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*
./python-2.4/lib/libjpeg.la
./python-2.4/lib/libjpeg.so.8
./python-2.4/lib/libjpeg.so
./python-2.4/lib/libjpeg.so.8.0.2
./python-2.4/lib/libjpeg.a

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

For more information see

How to test if PIL works

Example how to do it with system-wide Python:

wget http://upload.wikimedia.org/wikipedia/commons/b/bb/JohnCarrollGilbertStuart.jpg

python2.4

import PIL
from PIL import Image
im = Image.open("JohnCarrollGilbertStuart.jpg")
im.thumbnail((64, 64), Image.ANTIALIAS)
im.save("test.jpg")

No exceptions should be risen.

You can do the same thing in Zope console, started by:

bin/instance debug

目次

前のトピックへ

(例外)

次のトピックへ

(Buildout のトラブルシューティング)

このページ