Python 图像库失败并显示消息“解码器 JPEG 不可用” - 太平船务
PIL 在我的系统中确实支持 JPEG。
每当我上传时,我的代码都会失败:
File "PIL/Image.py", line 375, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
我该如何解决这个问题?
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
How can I resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
libjpeg-dev需要能够使用pillow(或PIL)处理jpeg,因此您需要安装它,然后重新编译pillow。 Ubuntu 14.04 上似乎还需要 libjpeg8-dev
如果您仍在使用 PIL,那么您这些天确实应该使用 PIL,所以在按照这些说明进行切换之前,首先
pip uninstall PIL
,或者如果您有充分的理由坚持使用 PIL,请在下面将“pillow”替换为“PIL”)。在 Ubuntu 上:
如果这不起作用,请尝试以下方法之一,具体取决于您使用的是 64 位还是 32 位 Ubuntu。
对于 Ubuntu x64:
或对于 Ubuntu 32 位:
然后重新安装枕头:(
编辑以包括评论反馈。感谢 Charles Offenbacher 指出这对于 32 位而言有所不同,并感谢 t-mart 建议使用
--no-cache-dir )。
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
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).On Ubuntu:
If that doesn't work, try one of the below, depending on whether you are on 64bit or 32bit Ubuntu.
For Ubuntu x64:
Or for Ubuntu 32bit:
Then reinstall 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
).对于 OSX 上的用户,我使用以下二进制文件在系统范围内安装 libpng 和 libjpeg:
libpng & libjpeg for OSX
因为我已经安装了 PIL(通过 virtualenv 上的 pip),所以我运行:
这为我解决了
decoder JPEG not available
错误。更新 (4/24/14):
较新版本的 pip 需要额外的标志才能从外部源下载库(包括 PIL)。尝试以下操作:
请参阅以下答案以获取其他信息:pip install PIL 不要安装到 virtualenv
UPDATE 2:
如果在 OSX Mavericks 上,您需要将
ARCHFLAGS
标志设置为 @RicardoGonzales 评论如下:For those on OSX, I used the following binary to get libpng and libjpeg installed systemwide:
libpng & libjpeg for OSX
Because I already had PIL installed (via pip on a virtualenv), I ran:
This resolved the
decoder JPEG not available
error for me.UPDATE (4/24/14):
Newer versions of pip require additional flags to download libraries (including PIL) from external sources. Try the following:
See the following answer for additional info: pip install PIL dont install into virtualenv
UPDATE 2:
If on OSX Mavericks, you'll want to set the
ARCHFLAGS
flag as @RicardoGonzales comments below:这是唯一对我有用的方法。安装软件包并重新安装 PIL 不起作用。
在 ubuntu 上,安装所需的软件包:(
您可能还需要安装 libfreetype6 libfreetype6-dev zlib1g-dev 以启用其他解码器)。
然后用pillow替换PIL:
This is the only way that worked for me. Installing packages and reinstalling PIL didn't work.
On ubuntu, install the required package:
(you may also want to install
libfreetype6 libfreetype6-dev zlib1g-dev
to enable other decoders).Then replace PIL with pillow:
以下内容适用于 ubuntu 12.04:
当您看到“-- JPEG support avaliable”时,表示它可以工作。
但是,如果编辑 jpeg 图像时仍然不起作用,请检查 python 路径!
我的 python 路径错过了
/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/
,所以我编辑~/.bashrc
将以下代码添加到此文件中:编辑:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/
然后,终于,它起作用了!
The followed works on ubuntu 12.04:
when your see "-- JPEG support avaliable" that means it works.
But, if it still doesn't work when your edit your jpeg image, check the python path !!
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:Edit:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/
then, finally, it works!!
在 Fedora 17 上,我必须安装
libjpeg-devel
,然后重新安装PIL
:On Fedora 17 I had to install
libjpeg-devel
and afterwards reinstallPIL
:Rolo 的答案非常好,但是我必须通过绕过 pip 缓存(与 pip 7 一起引入)来重新安装 Pillow,否则它将无法正确重新编译!
命令是:
你可以通过在日志中阅读以下内容来查看 Pillow 是否已正确配置:
如你所见,启用了对 jpg、tiff 等的支持,因为我之前通过 apt 安装了所需的库(libjpeg-dev libpng12-dev libfreetype6-dev libtiff-dev)
Rolo's answer is excellent, however I had to reinstall Pillow by bypassing pip cache (introduced with pip 7) otherwise it won't get properly recompiled!!!
The command is:
and you can see if Pillow has been properly configured by reading in the logs this:
as you can see the support for jpg, tiff and so on is enabled, because I previously installed the required libraries via apt (libjpeg-dev libpng12-dev libfreetype6-dev libtiff-dev)
在 Mac OS X Mavericks (10.9.3) 上,我通过执行以下操作解决了这个问题:
通过 brew 安装 libjpeg (包管理系统)
重新安装枕头(我使用枕头而不是PIL)
On Mac OS X Mavericks (10.9.3), I solved this by doing the follows:
Install libjpeg by brew (package management system)
reinstall pillow (I use pillow instead of PIL)
安装这些并确保使用 pip 安装 PIL,因为我从源代码编译了它,并且由于某种原因它不起作用
Install these and be sure to install PIL with pip because I compiled it from source and for some reason it didn't work
我已经在使用
Pillow
并遇到了同样的错误。尝试按照其他人的建议安装
libjpeg
或libjpeg-dev
,但被告知已经安装了(较新的)版本。最后只需重新安装
Pillow
:I was already using
Pillow
and got the same error.Tried installing
libjpeg
orlibjpeg-dev
as suggested by others but was told that a (newer) version was already installed.In the end all it took was reinstalling
Pillow
:我太新手了,无法评论 zeantsoi 帖子;(。所以这是我需要做的事情才能在 10.9.1 上的 OSX 上解决
1) 安装 Xcode 工具(打开终端并执行:
xcode-select --install
) - 摘自这篇文章:Mac OS X 10.9 之后无法安装 PIL2)从以下链接安装 libpng 和 libjpeg 包(组合安装程序):http: //ethan.tira-thompson.com/Mac_OS_X_Ports.html
3) 重新启动(不确定是否强制)
4) 重新安装 PIL 并运行
pip install -I PIL
(因为我在出现问题之前最初安装了 PIL)希望这有帮助,不要混淆更多..._
oho
I'm too newbie to comment zeantsoi post ;(. So here his what I needed to do to solved on OSX on 10.9.1 the
1) install Xcode tools (open your terminal and execute:
xcode-select --install
) - taken from this post: Can't install PIL after Mac OS X 10.92) install libpng and libjpeg package (combo installer) from this link: http://ethan.tira-thompson.com/Mac_OS_X_Ports.html
3) reboot (not sure it was mandatory)
4) Re-install PIL with run
pip install -I PIL
(as I had initially installed PIL before having the issue)Hope this help and don't confuse more ...
_oho
这个问题是很久以前发布的,大多数答案也很旧了。因此,当我花了几个小时试图解决这个问题时,没有任何效果,我尝试了这篇文章中的所有建议。
当我尝试以 Django 头像形式上传 JPG 时,仍然遇到标准 JPEG 错误:
然后我检查了 Ubuntu 12.04 的存储库,并注意到
libjpeg
的一些额外包。我安装了这些,我的问题得到了解决:安装这些已删除的
libjpeg-dev
、libjpeg-turbo8-dev
和libjpeg8-dev
。希望这对 2015 年及以后的人有所帮助!
干杯
This question was posted quite a while ago and most of the answers are quite old too. So when I spent hours trying to figure this out, nothing worked, and I tried all suggestions in this post.
I was still getting the standard JPEG errors when trying to upload a JPG in my Django avatar form:
Then I checked the repository for Ubuntu 12.04 and noticed some extra packages for
libjpeg
. I installed these and my problem was solved:Installing these removed
libjpeg-dev
,libjpeg-turbo8-dev
, andlibjpeg8-dev
.Hope this helps someone in the year 2015 and beyond!
Cheers
同样的问题,
JPEG 支持可用
,但仍然出现IOError:解码器/编码器 jpeg 不可用
,除了我使用 Pillow 而不是 PIL。我尝试了上述所有方法以及更多方法,但在许多小时后,我意识到与
virtualenv
结合使用sudo pip install
并不能按我的预期工作代码>.愚蠢的我。使用 sudo 有效地在新 shell 中启动命令(我对此的理解可能不完全正确),其中 virtualenv 未激活,这意味着软件包将安装在而是全球环境。 (这把事情搞砸了,我想我有 2 个不同的 Pillow 安装。)
我清理了一切,将用户更改为 root 并在 virtualenv 中重新安装,现在它可以工作了。
希望这会对某人有所帮助!
Same problem here,
JPEG support available
but still gotIOError: decoder/encoder jpeg not available
, except I use Pillow and not PIL.I tried all of the above and more, but after many hours I realized that using
sudo pip install
does not work as I expected, in combination withvirtualenv
. Silly me.Using
sudo
effectively launches the command in a new shell (my understanding of this may not be entirely correct) where the virtualenv is not activated, meaning that the packages will be installed in the global environment instead. (This messed things up, I think I had 2 different installations of Pillow.)I cleaned things up, changed user to root and reinstalled in the virtualenv and now it works.
Hopefully this will help someone!
对于 Fedora
安装先决条件
sudo dnf install make automake gcc gcc-c++ kernel-devel rpm-build libjpeg-devel zlib-devel python-devel
现在安装 Pillow
sudo pip installpillow
注意 - 对于 libjpeg 和 zlib,我们正在 Fedora/CentOS/ 中安装 libjpeg-devel 和 zlib-devel 软件包红帽
For Fedora
Install pre-requisite
sudo dnf install make automake gcc gcc-c++ kernel-devel rpm-build libjpeg-devel zlib-devel python-devel
Now install Pillow
sudo pip install pillow
Note - For libjpeg and zlib we are installing libjpeg-devel and zlib-devel packages in Fedora/CentOS/Red Hat
首先,除了卸载 Python 之外,我还必须删除隐藏文件夹 user/appData 中的 python 文件夹(这令人头疼)。然后我安装了 WinPython 发行版: http://code.google.com/p/winpython/其中包括 PIL
First I had to delete the python folders in hidden folder user/appData (that was creating huge headaches), in addition to uninstalling Python. Then I installed WinPython Distribution: http://code.google.com/p/winpython/ which includes PIL
对于 Mac OS Mountain Lion 上的用户,我遵循了 zeantsoi 的 anwser,但它不起作用。
我最终得到了这篇文章的解决方案: http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/
现在,我很高兴运行 jpeg 脚本!
For those on Mac OS Mountain Lion, I followed the anwser of zeantsoi, but it doesn't work.
I finally ended up with the solution of this post: http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/
Now, I'm happily running my script for jpeg !