15

我正在关注一个涉及图像上传的 Django 教程,并遇到了这个问题。我尝试多次安装和重新安装 PIL、libjpeg 和 libfreetype6,但到目前为止似乎没有任何效果。我花了几个小时试图找到一个解决方案,在这一点上我感到非常沮丧。请帮忙。

这是我在 Mac 上重新安装 PIL 后 selftest.py 的结果:

PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version       1.1.6
platform      darwin 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43)
              [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
--------------------------------------------------------------------
--- TKINTER support ok
*** JPEG support not available
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.
rrdhcp-10-32-44-157:Imaging-1.1.6 pfg$ python selftest.py
*****************************************************************
Failure in example: _info(Image.open("Images/lena.jpg"))
from line #24 of selftest.testimage
Exception raised:
Traceback (most recent call last):
  File "./doctest.py", line 499, in _run_examples_inner
    exec compile(source, "<string>", "single") in globs
  File "<string>", line 1, in <module>
  File "./selftest.py", line 22, in _info
    im.load()
  File "PIL/ImageFile.py", line 180, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "PIL/Image.py", line 375, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
1 items had failures:
   1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.
4

4 回答 4

42

PIL 有几个案例导致了类似的经历。如果您已使用 virtualenv 从 virtualenv 安装 PIL

pip install PIL

那么你应该已经安装了libjpeg,libz的开发版本。假设你在一个 Ubuntu 机器上,一个

pip uninstall PIL
apt-get install libjpeg-dev zlib1g-dev libpng12-dev
pip install PIL

应该足够了。您也可以安装Pillow而不是 PIL,它与 setuptools 配合使用效果更好,并且可以安装在 virtualenv 中。

于 2012-09-24T09:08:30.090 回答
7

我发现这对我来说很好:

pip uninstall PIL
pip install Pillow

然后我重新启动了服务器:

kill -HUP XXX

其中XXX是您的服务器进程的进程 ID。

于 2013-08-19T23:06:24.107 回答
5

我已经在使用Pillow并得到同样的错误。尝试安装libjpeglibjpeg-dev按照其他人的建议,但被告知已经安装了(更新的)版本。

最后只需要重新安装Pillow

sudo pip uninstall Pillow
sudo pip install Pillow
于 2014-08-20T13:33:30.137 回答
0

如果您使用 Fedora,请在执行 pip install Pillow 之前执行以下操作:

yum install libjpeg-devel zlib1g-devel libpng12-devel
于 2014-10-15T15:10:44.337 回答