Python 图像库失败并显示消息“解码器 JPEG 不可用” - 太平船务

发布于 2024-12-27 19:56:10 字数 241 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

东风软 2025-01-03 19:56:10

libjpeg-dev需要能够使用pillow(或PIL)处理jpeg,因此您需要安装它,然后重新编译pillow。 Ubuntu 14.04 上似乎还需要 libjpeg8-dev

如果您仍在使用 PIL,那么您这些天确实应该使用 PIL,所以在按照这些说明进行切换之前,首先 pip uninstall PIL ,或者如果您有充分的理由坚持使用 PIL,请在下面将“pillow”替换为“PIL”)。

在 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。

对于 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 位:

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 )。

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:

# 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.

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

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/

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).

白鸥掠海 2025-01-03 19:56:10

对于 OSX 上的用户,我使用以下二进制文件在系统范围内安装 libpng 和 libjpeg:

libpng & libjpeg for OSX

因为我已经安装了 PIL(通过 virtualenv 上的 pip),所以我运行:

pip uninstall PIL
pip install PIL --upgrade

这为我解决了 decoder JPEG not available 错误。

更新 (4/24/14)

较新版本的 pip 需要额外的标志才能从外部源下载库(包括 PIL)。尝试以下操作:

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

请参阅以下答案以获取其他信息:pip install PIL 不要安装到 virtualenv

UPDATE 2:

如果在 OSX Mavericks 上,您需要将 ARCHFLAGS 标志设置为 @RicardoGonzales 评论如下

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

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:

pip uninstall PIL
pip install PIL --upgrade

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:

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

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:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install PIL --allow-external PIL --allow-unverified PIL
太阳公公是暖光 2025-01-03 19:56:10

这是唯一对我有用的方法。安装软件包并重新安装 PIL 不起作用。

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

sudo apt-get install libjpeg-dev

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

然后用pillow替换PIL:

pip uninstall PIL
pip install pillow

This is the only way that worked for me. Installing packages and reinstalling PIL didn't work.

On ubuntu, install the required package:

sudo apt-get install libjpeg-dev

(you may also want to install libfreetype6 libfreetype6-dev zlib1g-dev to enable other decoders).

Then replace PIL with pillow:

pip uninstall PIL
pip install pillow
我早已燃尽 2025-01-03 19:56:10

以下内容适用于 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

当您看到“-- 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:

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.

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!!

澜川若宁 2025-01-03 19:56:10

在 Fedora 17 上,我必须安装 libjpeg-devel,然后重新安装 PIL

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

On Fedora 17 I had to install libjpeg-devel and afterwards reinstall PIL:

sudo yum install --assumeyes libjpeg-devel
sudo pip-python install --upgrade PIL
予囚 2025-01-03 19:56:10

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)

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:

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

and you can see if Pillow has been properly configured by reading in the logs this:

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
    --------------------------------------------------------------------

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)

想你的星星会说话 2025-01-03 19:56:10

在 Mac OS X Mavericks (10.9.3) 上,我通过执行以下操作解决了这个问题:

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

brew 安装 libjpeg

重新安装枕头(我使用枕头而不是PIL)

pip install -I 枕头

On Mac OS X Mavericks (10.9.3), I solved this by doing the follows:

Install libjpeg by brew (package management system)

brew install libjpeg

reinstall pillow (I use pillow instead of PIL)

pip install -I pillow

一个人的旅程 2025-01-03 19:56:10
apt-get install libjpeg-dev
apt-get install libfreetype6-dev
apt-get install zlib1g-dev
apt-get install libpng12-dev

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

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

Install these and be sure to install PIL with pip because I compiled it from source and for some reason it didn't work

心作怪 2025-01-03 19:56:10

我已经在使用 Pillow 并遇到了同样的错误。
尝试按照其他人的建议安装libjpeglibjpeg-dev,但被告知已经安装了(较新的)版本。

最后只需重新安装 Pillow

sudo pip uninstall Pillow
sudo pip install Pillow

I was already using Pillow and got the same error.
Tried installing libjpeg or libjpeg-dev as suggested by others but was told that a (newer) version was already installed.

In the end all it took was reinstalling Pillow:

sudo pip uninstall Pillow
sudo pip install Pillow
如歌彻婉言 2025-01-03 19:56:10

我太新手了,无法评论 zeantsoi 帖子;(。所以这是我需要做的事情才能在 10.9.1 上的 OSX 上解决

IOError:解码器 jpeg 不可用

1) 安装 Xcode 工具(打开终端并执行:xcode-select --install) - 摘自这篇文章:Mac OS X 10.9 之后无法安装 PIL

2)从以下链接安装 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

IOError: decoder jpeg not available

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.9

2) 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

千纸鹤 2025-01-03 19:56:10

这个问题是很久以前发布的,大多数答案也很旧了。因此,当我花了几个小时试图解决这个问题时,没有任何效果,我尝试了这篇文章中的所有建议。

当我尝试以 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-devlibjpeg-turbo8-devlibjpeg8-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:

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

Then I checked the repository for Ubuntu 12.04 and noticed some extra packages for libjpeg. I installed these and my problem was solved:

sudo apt-get install libjpeg62 libjpeg62-dev

Installing these removed libjpeg-dev, libjpeg-turbo8-dev, and libjpeg8-dev.

Hope this helps someone in the year 2015 and beyond!

Cheers

£烟消云散 2025-01-03 19:56:10

同样的问题,JPEG 支持可用,但仍然出现 IOError:解码器/编码器 jpeg 不可用,除了我使用 Pillow 而不是 PIL。

我尝试了上述所有方法以及更多方法,但在许多小时后,我意识到与virtualenv结合使用sudo pip install并不能按我的预期工作代码>.愚蠢的我。

使用 sudo 有效地在新 shell 中启动命令(我对此的理解可能不完全正确),其中 virtualenv 未激活,这意味着软件包将安装在而是全球环境。 (这把事情搞砸了,我想我有 2 个不同的 Pillow 安装。)

我清理了一切,将用户更改为 root 并在 virtualenv 中重新安装,现在它可以工作了。
希望这会对某人有所帮助!

Same problem here, JPEG support available but still got IOError: 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 with virtualenv. 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!

π浅易 2025-01-03 19:56:10

对于 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-develzlib-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

就此别过 2025-01-03 19:56:10

首先,除了卸载 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

这样的小城市 2025-01-03 19:56:10

对于 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 !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文