Search code examples
pythonpython-imaging-libraryzliblibjpeg

PIL zip jpeg decoders not working on runtime but work on install/selftest


I'm running Debian 6 and recently installed PIL.

I have preinstalled the zlib and jpeg libraries, and they're both on /usr/lib

When installing, the setup.py file finds the libraries, I get the standard:

--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.3 (default, Jun 29 2012, 22:38:23)
              [GCC 4.4.5]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available

zlib and jpeg are working as expected. Running selftest.py also succeeds

--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
*** TKINTER support not installed
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--- LITTLECMS support ok
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.

So we're rejoicing so far.

Just to make sure, we run python and test that zlib decoder works

Python 2.7.3 (default, Jun 29 2012, 22:38:23)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
>>> a=zlib.compress('hello world')
>>> print zlib.decompress(a)
hello world

So, it works.

However, when I try to save an Image:

>>> import Image
>>> i = Image.open('a.png')
>>> i.save('b.png')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/PIL/Image.py", line 1406, in save
    self.load()
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageFile.py", line 189, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "/usr/local/lib/python2.7/site-packages/PIL/Image.py", line 385, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available

Same error if I try to save as jpeg (except the jpeg decoder is the unavailable one)

If I check Image.core, I see that, in fact, there's no zip_decoder nor jpeg_decoder attributes.

>>> dir(Image.core)
['__doc__', '__file__', '__name__', '__package__', 'bit_decoder', 'blend', 'convert',
'copy', 'crc32', 'draw', 'effect_mandelbrot', 'effect_noise', 'eps_encoder', 'fill', 
'fli_decoder', 'font', 'getcodecstatus', 'getcount', 'gif_decoder', 'gif_encoder',
'hex_decoder', 'hex_encoder', 'linear_gradient', 'map_buffer', 'msp_decoder', 'new', 
'open_ppm', 'outline', 'packbits_decoder', 'path', 'pcd_decoder', 'pcx_decoder', 
'pcx_encoder', 'radial_gradient', 'raw_decoder', 'raw_encoder', 'sun_rle_decoder', 
'tga_rle_decoder', 'tiff_lzw_decoder', 'wedge', 'xbm_decoder', 'xbm_encoder']

I can't find out what it is, as I see it, even though it FINDS the proper libraries on installation (so it's not a problem of the setup not finding the library, it finds them), the core object is created without the proper decoders.

Have tried reinstalling PIL lots of times, checking the permissions on the /usr/lib directories and .so files. Running PIL as root to see if there's any kind of problem. But still there's no answer.

If anyone could help with this, it'd be great!

Thanks in advance.

Bruno


Solution

  • A simple way to solve the problem is using Pillow not PIL.

    Pillow is the "friendly" PIL fork. PIL is the Python Imaging Library. Pillow was started for and is currently maintained by the Plone community. But it is used by many other folks in the Python web community, and probably elsewhere too.

    Firstly,pip uninstall PIL removes installed PIL,

    then, type pip install pillow.