【问题标题】:"IOError: decoder zip not available" : Ubuntu Python PIL“IOError:解码器 zip 不可用”:Ubuntu Python PIL
【发布时间】:2013-02-21 21:25:16
【问题描述】:

我正在尝试从以下位置运行示例 heatmap.py: http://jjguy.com/heatmap/

#image.py
import heatmap
import random

if __name__ == "__main__":    
    pts = []
    for x in range(400):
        pts.append((random.random(), random.random() ))

    print "Processing %d points..." % len(pts)

    hm = heatmap.Heatmap()
    img = hm.heatmap(pts)
    img.save("classic.png")

我得到这个错误:

Processing 400 points...
Traceback (most recent call last):
  File "/home/ec2usr/workspace/image/image.py", line 14, in <module>
    img.save("classic.png")
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1437, in save
    save_handler(self, fp, filename)
  File "/usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.py", line 572, in _save
    ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)])
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 481, in _save
    e = Image._getencoder(im.mode, e, a, im.encoderconfig)
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 399, in _getencoder
    raise IOError("encoder %s not available" % encoder_name)
IOError: encoder zip not available

在 Ubuntu 12(64 位)系统上使用 Eclipse,使用 Python 2.7。

我在 /usr/lib 和 /usr/lib/x86_64-linux-gnu/ 中都找到了 libz.so。我已经尝试了这些解决方案,但没有结果:

PIL says it has "support available" but still gives IOError when saving files

About the PIL Error -- IOError: decoder zip not available

IOError: "decoder zip not available" using matplotlib PNG in ReportLab on Linux, works on Windows

http://www.foxhop.net/ubuntu-python-easy_install-pil-does-not-install-zlib-support

我已经为此烦恼了几天,非常感谢任何人的帮助!

从 python-imaging 安装日志:

ubuntu@ip-10-241-17-21:/usr/lib$ sudo apt-get install python-imaging
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  account-plugin-identica account-plugin-twitter gir1.2-messagingmenu-1.0
  hplip-data libgtkspell-3-0 libqt4-designer libqt4-help libqt4-scripttools
  libqt4-svg libqt4-test libqtassistantclient4 libsane-hpaio
  linux-headers-3.5.0-21 linux-headers-3.5.0-21-generic python-debtagshw
  python-lxml python-pexpect python-piston-mini-client python-qt4
  python-renderpm python-reportlab python-reportlab-accel python-sip
  software-center-aptdaemon-plugins ubuntu-extras-keyring
Use 'apt-get autoremove' to remove them.
Suggested packages:
  python-imaging-doc python-imaging-dbg
The following NEW packages will be installed:
  python-imaging
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/294 kB of archives.
After this operation, 996 kB of additional disk space will be used.
Selecting previously unselected package python-imaging.
(Reading database ... 189302 files and directories currently installed.)
Unpacking python-imaging (from .../python-imaging_1.1.7-4build1_amd64.deb) ...
Setting up python-imaging (1.1.7-4build1) ...
ubuntu@ip-10-241-17-21:/usr/lib$

安装日志(python install setup.py from Imaging):

PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.3 (default, Sep 26 2012, 21:51:14)
              [GCC 4.7.2]
--------------------------------------------------------------------
--- TKINTER support available
*** JPEG support not available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available

selftest.py:

--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from /usr/local/lib/python2.7/dist-packages
--------------------------------------------------------------------
*** PIL CORE support not installed
*** TKINTER support not installed
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not installed
*** LITTLECMS support not installed
--------------------------------------------------------------------

【问题讨论】:

  • 你安装 PIL 时有libz.so吗?
  • 我相信是这样,但我后来也用 sudo apt-get build-dep python-imaging 重新安装了 PIL egg,以防万一。
  • 更新:.tif 工作正常; png 和 jpg 不起作用。
  • 另外,如果我没记错的话,PIL 会在安装过程中打印出支持和不支持的格式列表。
  • 刚刚从控制台添加了安装日志,没有看到任何格式。

标签: python python-imaging-library imaging


【解决方案1】:

我刚刚遇到了由 PIL(通过 python pip 安装程序安装)和通过 apt-get 安装的 python-imaging 包引起的类似问题。当我从 pip 中删除为我解决它的额外版本时。

如果您从源代码或使用 pip 安装 PIL,那么您可能会遇到同样的问题。

在构建 PIL 时,我还发现我必须将库链接到 /usr/lib。这可能会解决您上面的日志中不支持的消息。

sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib

【讨论】:

    【解决方案2】:

    我记得在 64 位系统上安装 PIL 时,我得到了与 Kris 完全相同的解决方案。

    但是现在我建议使用 Pillow(pip install 枕头)而不是 PIL。 Pillow 只是 PIL 的一个分支,具有更频繁的发布和更少的问题,例如您遇到的问题。

    如果您使用的是 Ubuntu,我认为您需要在安装 PIL/Pillow 之前安装 zlib1g-dev 和 libjpeg-dev, 以便获得对内置 jpeg/png 的支持。

    【讨论】:

    • 这里确认安装PIL/Pillow之前需要安装依赖,这样安装过程才会执行正确的编译步骤。
    • 这对我来说是正确的答案,它适用于带有 python 2.7 和 3.4 的 Ubuntu 12.04 和 14.04
    【解决方案3】:

    即使我的 PIL 是最新的,我在 Ubuntu 12.04 上解决了这个问题:

    pip uninstall PIL
    pip install PIL
    

    【讨论】:

      【解决方案4】:

      这对我来说非常有效:

      apt-get install libjpeg62 libjpeg62-dev zlib1g-dev libfreetype6 libfreetype6-dev
      

      在 x86_64 中:

      ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
      ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
      ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib
      

      在 i386 中:

      ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/
      ln -s /usr/lib/i386-linux-gnu/libfreetype.so.6 /usr/lib/
      ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/
      
      
      pip install -U PIL --allow-external PIL --allow-unverified PIL
      pip install -I pillow
      

      【讨论】:

        【解决方案5】:

        即使你用

        测试

        从 PIL 导入图像

        没问题,但保存/解码方法仍有错误。

        你可以试试我的步骤:(根据我的情况,openerp 7 和 ubuntu 13.10)

        1. 删除 python 图像
        2. 找到你的 libz
        3. 重新安装 PIL

        检查一下http://febru.soluvas.com/2014/03/solved-openerp-7-ioerror-decoder-zip.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-04-02
          • 2020-05-29
          • 1970-01-01
          相关资源
          最近更新 更多