Python图像库失败,消息“解码器JPEG不可用” - PIL

本文翻译自:Python Image Library fails with message “decoder JPEG not available” - PIL

PIL does support JPEG in my system. PIL在我的系统中支持JPEG。

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

How can I resolve this? 我该如何解决这个问题?


#1楼

参考:https://stackoom.com/question/bPH6/Python图像库失败-消息-解码器JPEG不可用-PIL


#2楼

libjpeg-dev is required to be able to process jpegs with pillow (or PIL), so you need to install it and then recompile pillow. libjpeg-dev需要能够使用枕头(或PIL)处理jpegs,因此您需要安装它然后重新编译枕头。 It also seems that libjpeg8-dev is needed on Ubuntu 14.04 似乎在Ubuntu 14.04上需要libjpeg8-dev

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). 如果你还在使用PIL,那么你最近应该使用枕头,所以在按照这些说明进行切换之前,请先pip uninstall PIL ,或者如果你有充分的理由坚持使用PIL,那么用“PIL”替换“枕头”在下面)。

On Ubuntu: 在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

If that doesn't work, try one of the below, depending on whether you are on 64bit or 32bit Ubuntu. 如果这不起作用,请尝试以下其中一项,具体取决于您使用的是64位还是32位Ubuntu。

For Ubuntu x64: 对于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

Or for Ubuntu 32bit: 或者对于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/

Then reinstall pillow: 然后重新安装枕头:

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

(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 ). (编辑包括来自评论的反馈。感谢Charles Offenbacher指出这与32位不同,而t-mart建议使用--no-cache-dir )。


#3楼

For those on OSX, I used the following binary to get libpng and libjpeg installed systemwide: 对于OSX上的那些人,我使用以下二进制文件来获得系统安装的libpng和libjpeg:

libpng & libjpeg for OSX 用于OSX的libpng和libjpeg

Because I already had PIL installed (via pip on a virtualenv), I ran: 因为我已经安装了PIL(通过virtualenv上的pip),我跑了:

pip uninstall PIL
pip install PIL --upgrade

This resolved the decoder JPEG not available error for me. 这为我解决了decoder JPEG not available错误。

UPDATE (4/24/14) : 更新(2014年4月24日)

Newer versions of pip require additional flags to download libraries (including PIL) from external sources. 较新版本的pip需要额外的标志才能从外部源下载库(包括PIL)。 Try the following: 请尝试以下方法:

pip install PIL --allow-external PIL --allow-unverified PIL

See the following answer for additional info: pip install PIL dont install into virtualenv 有关其他信息,请参阅以下答案: pip install PIL不要安装到virtualenv中

UPDATE 2 : 更新2

If on OSX Mavericks, you'll want to set the ARCHFLAGS flag as @RicardoGonzales comments below : 如果在OSX Mavericks上,您需要将ARCHFLAGS标志设置为@RicardoGonzales评论如下

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install PIL --allow-external PIL --allow-unverified PIL

#4楼

On Fedora 17 I had to install libjpeg-devel and afterwards reinstall PIL : 在Fedora 17上,我必须安装libjpeg-devel ,然后重新安装PIL

sudo yum install --assumeyes libjpeg-devel
sudo pip-python install --upgrade PIL

#5楼

First I had to delete the python folders in hidden folder user/appData (that was creating huge headaches), in addition to uninstalling Python. 首先,除了卸载Python之外,我还必须删除隐藏文件夹user / appData中的python文件夹(这会产生巨大的麻烦)。 Then I installed WinPython Distribution: http://code.google.com/p/winpython/ which includes PIL 然后我安装了WinPython Distribution: http//code.google.com/p/winpython/ ,其中包含PIL


#6楼

The followed works on ubuntu 12.04: 以下是关于ubuntu 12.04的工作:

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

when your see "-- JPEG support avaliable" that means it works. 当你看到“ - JPEG支持avaliable”,这意味着它的工作原理。

But, if it still doesn't work when your edit your jpeg image, check the python path !! 但是,如果在编辑jpeg图像时仍然无效,请检查python路径! my python path missed /usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/ , so I edit the ~/.bashrc add the following code to this file: 我的python路径错过了/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/ ,所以我编辑~/.bashrc将以下代码添加到此文件:

Edit: export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/ 编辑: export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/

then, finally, it works!! 最后,它的确有效!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章