python - 遵循 Django 照片应用程序教程时解码器 JPEG 不可用错误

标签 python django jpeg python-imaging-library

我正在学习一个涉及图片上传的 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.

最佳答案

有几个 PIL 案例导致了类似的经历。 如果你已经使用

从 virtualenv 安装了 PIL
pip install PIL

那么你之前应该已经安装了libjpeg、libz的dev版本。 假设您使用的是 Ubuntu 机器,

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

应该够了。您还可以安装 Pillow代替 PIL,它与 setuptools 一起工作得更好,并且可以安装在 virtualenv 中。

关于python - 遵循 Django 照片应用程序教程时解码器 JPEG 不可用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12555831/

相关文章:

python - 使用 Python 的 App Engine : How to convert pdf file into different jpeg images

image-processing - 图像识别算法的学习步骤

python - Random.shuffle 出人意料地在循环内不起作用

python - 通过 UDP 数据包发送字节,无需进一步转换

python - 带有生成器表达式的 asyncio.gather

python - Wagtail-ModelTranslation 模板片段缓存

python - 通过 C-api 分析 Python(如何?)

django - 将Django DateField格式化为ISO格式

python - Django-Debug-Toolbar 未显示(不允许的 MIME 类型)

python - 将 jpeg 字符串转换为 PIL 图像对象