PIL zip jpeg解码器不能在运行时工作,但可以在install/selftest上工作

Bru*_*uno 1 python zlib libjpeg python-imaging-library

我正在运行Debian 6并且最近安装了PIL.

我预先安装了zlib和jpeg库,它们都在/ usr/lib上

安装时,setup.py文件找到库,我得到标准:

--------------------------------------------------------------------
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
Run Code Online (Sandbox Code Playgroud)

zlib和jpeg按预期工作.运行selftest.py也会成功

--------------------------------------------------------------------
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.
Run Code Online (Sandbox Code Playgroud)

所以到目前为止我们都很高兴.

为了确保,我们运行python并测试zlib解码器的工作原理

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
Run Code Online (Sandbox Code Playgroud)

所以,它的工作原理.

但是,当我尝试保存图像时:

>>> 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
Run Code Online (Sandbox Code Playgroud)

如果我尝试保存为jpeg(jpeg解码器不可用),则会出现同样的错误

如果我检查Image.core,我看到,实际上,没有zip_decoder和jpeg_decoder属性.

>>> 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']
Run Code Online (Sandbox Code Playgroud)

我无法找到它是什么,正如我所看到的,即使它在安装时找到合适的库(因此它不是设置没有找到库的问题,它找到它们),核心对象是在没有它的情况下创建的.适当的解码器.

尝试过很多次重新安装PIL,检查/ usr/lib目录和.so文件的权限.以root身份运行PIL以查看是否存在任何问题.但仍然没有答案.

如果有人能帮忙解决这个问题,那就太好了!

提前致谢.

布鲁诺

iMo*_*om0 5

解决问题的一种简单方法是使用Pillow not PIL.

枕头是"友好"的PIL叉.PIL是Python Imaging Library.Pillow开始使用,目前由Plone社区维护.但它被Python网络社区中的许多其他人使用,也可能在其他地方使用.

首先,pip uninstall PIL删除已安装的PIL,

然后,键入pip install pillow.