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!! 最後,它的確有效!

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