关于PIL错误-- IOError: 解码器zip不可用

70

我正在收到:

IOError: decoder zip not available

当我尝试在PIL中绘制一张图片并将其保存为jpeg格式时,遇到了问题。有什么想法来解决这个问题吗?在查看/上传图像方面,PIL对我来说一直都很好用。

16个回答

116
sudo pip uninstall PIL
sudo pip install pillow 

^^对我很有帮助。

Pillow是PIL的一个分支,兼容pip/setuptools并得到了更好的维护。我还没有看到任何API差异。

编辑:有一个值得注意的API差异。PIL公开了Image作为顶级命名空间,因此您可以

import Image # in PIL only

但是

from PIL import Image  # in pillow or PIL
  • 谢谢,Leopd!

4
问题解决了!这比手动编译PIL要简单得多。谢谢! - surj
7
小差异 - PIL 中 import Image 可以工作,但在 Pillow 中不行。Pillow 需要使用 from PIL import Image - Leopd
这也解决了在此描述的问题:http://osdir.com/ml/python-numeric-general/2009-07/msg00124.html,其中numpy数组实际上并没有创建一个数组,而是类似于<PngImagePlugin.PngImageFile instance at 0xd1a050>(根据图像类型不同可能会有所不同)。我认为API的变化也很有意义... - Sebastian Blask
4
在运行pillow安装之前,建议使用"sudo apt-get install libjpeg-dev zlib1g-dev"安装zlib和jpeg dev头文件。这将确保.png和.jpg的导出正常工作并进行编译。 - meawoppl
3
在OS X Mavericks上没有帮助 :( - Petr Peller
1
如果在安装zlib后重新安装Pillow,则需要重新编译Pillow:pip --no-cache-dir install Pillow - Tianwei Chen

41

2
懒人专用:sudo apt-get install libjpeg-dev zlib1g-dev - meawoppl
1
如果您正在为Pebble开发,并因zip解码器不可用而来到这里,请安装这些库并重新安装pillow。再次安装pillow将使用这些依赖项重新构建库。 - HyLian
如果这对你不起作用,请看一下JohnPang的答案,它对我有用。 - Mark O'Sullivan

17

我在一台64位的ubuntu 13.04桌面版遇到了这个问题,以下是我是如何解决的。

尝试重新安装PIL,并注意重新安装后的输出信息:

---------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.4 (default, Sep 26 2013, 03:20:26)
              [GCC 4.7.3]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
*** ZLIB (PNG/ZIP) support not available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------

请注意这一行:*** ZLIB (PNG/ZIP) support not available,意味着PIL没有构建ZLIB支持,我通过以下方式进行了修复:

首先您需要安装这些软件包:libjpeg-dev libfreetype6-dev zlib1g-dev

sudo apt-get install python-dev libjpeg-dev libfreetype6-dev zlib1g-dev

# create these links, if already exists, remove it and re-link it
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

# reinstall PIL
pip uninstall PIL
pip install PIL

这次输出中应该有一行 --- ZLIB(PNG/ZIP)支持可用

参考: http://jj.isgeek.net/2011/09/install-pil-with-jpeg-support-on-ubuntu-oneiric-64bits/


如果您在执行此操作后看到“_imagingft.c:73:31: fatal error: freetype/fterrors.h: No such file or directory”错误,请链接另一个库:ln -s /usr/include/freetype2 /usr/include/freetype2/freetype(我相信这是由于您安装了“apt-get install python-imaging”引起的)。 - Nick Sweeting

13

这可能只需要zip解码器就能保存JPEG文件。我认为在OS X中,我需要按照以下步骤来预览JPEG文件:

这可能意味着你需要:


1
你可以下载zlib,然后使用pip重新安装pil。你不需要从源代码构建它。 - leech
Mac OS X PIL JEPG 和 PNG 问题这篇文章帮助我解决了使用 PIL 时遇到的 PNG 和 JPEG 问题(包括“decoder zip not available”和“decoder jpeg not available”)。 - isaacselement

9

我遇到了同样的问题。看起来Pillow和pillow('p'的大小写不同)是两个不同的软件包。所以,如果你正在使用Pillow,pip install pillow可能无法解决问题。这是我的解决方案:

$ pip uninstall Pillow
$ sudo apt-get install libjpeg-dev zlib1g-dev
$ pip install -I Pillow

首先,前两行代码是为了卸载任何已安装的pillow或Pillow包。

第三行代码是用来安装两个必需的包。

第四行代码是重新安装Pillow。

请注意,如果您正在使用虚拟环境,则必须在虚拟环境下运行pip install/uninstall命令。


2

1
我使用64位的Ubuntu 14.04LTS桌面版,并尝试了Johnny Zhao的答案。

exec sudo easy_install PIL

我收到一个错误:

can't find freetype/fterrors.h

我在 /usr/include/ 中找到了 freetype2。

你可以通过以下方法解决:

sudo ln -s /usr/include/freetype2 /usr/include/freetype

然后安装将成功


这是因为你使用apt-get install python-imaging安装了python-imaging。如果只单独安装libjpeg-dev libfreetype6-dev zlib1g-dev而不安装所有的python-imaging,就不会出现这个错误。 - Nick Sweeting

1
在Mac上
sudo brew install lzlib     # installs zlib
pip uninstall PIL
pip install PIL

请详细说明一些。很难理解你的意思。 - Robbie Wxyz
在我的电脑上,输入sudo brew install lzlib只会显示"brew: command not found"。 - Almo

1
可能的原因是您安装了没有zlib支持的Pillow。
在CentOS 7上:
yum install zlib zlib-devel
pip install Pillow --upgrade

如果您正在使用的是Web应用程序,请重新启动您的Web服务器以应用更改。


1
这可能很明显,但如果您正在使用virtualenv,则应在其中执行“pip install Pillow --upgrade”。 - shawn

0

Mac OS X PIL JEPG和PNG问题(Linux操作系统也一样),这篇文章帮助我解决了PIL的PNG和JPEG问题: 解码器zip不可用解码器jpeg不可用

在安装/重新安装PIL时,请确保JPEG和ZLIB可用:

$ cd Imaging-1.1.7
$ python setup.py build_ext -i
$ python selftest.py

--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接