PIL在我的系统中支持JPEG。

每当我做一个上传,我的代码失败:

File "PIL/Image.py", line 375, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available

我该如何解决这个问题?


当前回答

在Mac OS X Mavericks(10.9.3)上,我通过以下方法解决了这个问题:

通过brew安装libjpeg(包管理系统)

编译libjpeg

重新安装枕头(我用枕头代替PIL)

pip安装-I枕

其他回答

apt-get install libjpeg-dev
apt-get install libfreetype6-dev
apt-get install zlib1g-dev
apt-get install libpng12-dev

安装这些并确保使用pip安装PIL,因为我从源代码编译了它,由于某种原因它无法工作

对于那些使用Mac OS Mountain Lion的人,我使用zeantsoi的答案,但它不起作用。

我最终得到了这篇文章的解决方案:http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/

现在,我很高兴地运行我的jpeg脚本!

这是唯一对我有效的方法。安装包和重新安装PIL都不起作用。

在ubuntu上,安装所需的软件包:

sudo apt-get install libjpeg-dev

(您可能还需要安装libfreetype6 libfreetype6-dev zlib1g-dev来启用其他解码器)。

然后将PIL替换为pillow:

pip uninstall PIL
pip install pillow

这个问题是很久以前发布的,大多数答案也很老了。所以当我花了几个小时试图弄清楚这个问题时,什么都没用,我尝试了这篇文章中的所有建议。

当我试图在我的Django头像表单中上传JPG时,我仍然会得到标准的JPEG错误:

raise IOError("decoder %s not available" % decoder_name)
OSError: decoder jpeg not available

然后我检查了Ubuntu 12.04的存储库,注意到一些额外的libjpeg包。我安装了这些,问题就解决了:

sudo apt-get install libjpeg62 libjpeg62-dev

安装这些程序将删除libjpeg-dev、libjpeg-turbo8-dev和libjpeg8-dev。

希望这对2015年及以后的人们有所帮助!

干杯

Rolo的回答非常棒,但是我不得不通过绕过pip缓存(pip 7引入)重新安装Pillow,否则它将无法正确地重新编译!! 命令如下:

pip install -I --no-cache-dir -v Pillow

通过阅读日志,您可以查看Pillow是否已正确配置:

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.8.2
    platform     linux 3.4.3 (default, May 25 2015, 15:44:26)
                 [GCC 4.8.2]
    --------------------------------------------------------------------
    *** TKINTER support not available
    --- JPEG support available
    *** OPENJPEG (JPEG2000) support not available
    --- ZLIB (PNG/ZIP) support available
    --- LIBTIFF support available
    --- FREETYPE2 support available
    *** LITTLECMS2 support not available
    *** WEBP support not available
    *** WEBPMUX support not available
    --------------------------------------------------------------------

正如你所看到的,对jpg, tiff等的支持是启用的,因为我之前通过apt (libjpeg-dev libpng12-dev libfreetype6-dev libtiff-dev)安装了所需的库