Python图像库失败,并显示消息“解码器JPEG不可用". -PIL [英] Python Image Library fails with message "decoder JPEG not available" - PIL

查看:107
本文介绍了Python图像库失败,并显示消息“解码器JPEG不可用". -PIL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PIL在我的系统中确实支持JPEG.

PIL does support JPEG in my system.

每次上传时,我的代码都会失败并显示以下信息:

Whenever I do an upload, my code is failing with:

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

我该如何解决?

推荐答案

libjpeg-dev必须能够处理带有枕头(或PIL)的jpeg,因此您需要先安装它,然后重新编译枕头.在Ubuntu 14.04上似乎还需要libjpeg8-dev

libjpeg-dev is required to be able to process jpegs with pillow (or PIL), so you need to install it and then recompile pillow. It also seems that libjpeg8-dev is needed on Ubuntu 14.04

如果您仍在使用PIL,那么这些天您确实应该使用枕头,因此,在遵循以下说明进行切换之前,请先pip uninstall PIL,或者如果您有充分的理由坚持使用PIL,然后将枕头"替换为下方的"PIL".

If you're still using PIL then you should really be using pillow these days though, so first pip uninstall PIL before following these instructions to switch, or if you have a good reason for sticking with PIL then replace "pillow" with "PIL" in the below).

在Ubuntu上:

# install libjpeg-dev with apt
sudo apt-get install libjpeg-dev
# if you're on Ubuntu 14.04, also install this
sudo apt-get install libjpeg8-dev

# reinstall pillow
pip install --no-cache-dir -I pillow

如果这不起作用,请根据您使用的是64位还是32位Ubuntu,尝试以下方法之一.

If that doesn't work, try one of the below, depending on whether you are on 64bit or 32bit Ubuntu.

对于Ubuntu x64:

For Ubuntu x64:

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

或对于Ubuntu 32位:

Or for Ubuntu 32bit:

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

然后重新安装枕头:

pip install --no-cache-dir -I pillow

(进行编辑以包含评论的反馈.感谢Charles Offenbacher指出32位版本存在差异,而t-mart建议使用--no-cache-dir.)

(Edits to include feedback from comments. Thanks Charles Offenbacher for pointing out this differs for 32bit, and t-mart for suggesting use of --no-cache-dir).

这篇关于Python图像库失败,并显示消息“解码器JPEG不可用". -PIL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆