PIL在Ubuntu x64上无法解码JPEG

10

我知道这个问题看起来像是一个重复的问题,但是我已经遵循了许多在线指南,以正确安装PIL,并且都没有成功。

我尝试了stackoverflow上的Python Image Library fails with message "decoder JPEG not available" - PIL中的一切方法,但都没有成功。

当我运行sudo pip install pil时,最糟糕的是出现了一个误导性错误。Jpeg、Freetyle等支持都被列为可用。但是当使用PIL运行一些python代码时,会出现臭名昭著的“decoder jpeg not available”的IOError。

即使在/usr/lib中建立软链接到.so libjpeg文件,仍然没有任何效果。

有什么想法吗?谢谢。

1个回答

19
你可以试试这个:
1. 清除PIL包
rm -rf /usr/lib/python2.7/site-packages/PIL
rm -rf /usr/lib/python2.7/site-packages/PIL.pth

2. 安装必需的软件包

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

centos:
yum install zlib zlib-devel
yum install libjpeg libjpeg-devel
yum install freetype freetype-devel

3.下载镜像并安装

wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
tar xzvf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
# if the sys is x64, you must also do this: edit the setup.py file and set:
# centOS:
TCL_ROOT = '/usr/lib64'
JPEG_ROOT = '/usr/lib64'
ZLIB_ROOT = '/usr/lib64'
TIFF_ROOT = '/usr/lib64'
FREETYPE_ROOT = '/usr/lib64'
LCMS_ROOT = '/usr/lib64'
# Ubuntu:
TCL_ROOT = '/usr/lib/x86_64-linux-gnu'
JPEG_ROOT = '/usr/lib/x86_64-linux-gnu'
ZLIB_ROOT = '/usr/lib/x86_64-linux-gnu'
TIFF_ROOT = '/usr/lib/x86_64-linux-gnu'
FREETYPE_ROOT = '/usr/lib/x86_64-linux-gnu'
LCMS_ROOT = '/usr/lib/x86_64-linux-gnu'
#then install it use:
python2.7 setup.py install

4. 检查是否生效

# before this command you should run `mv PIL PIL2`

python2.7 selftest.py

如果结果是:
--- PIL CORE support ok
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
*** LITTLECMS support not installed
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.

恭喜你!

我正在尝试解决问题,但是出现了“ImproperlyConfigured: Error importing module”的错误,提示“没有名为PIL的模块”。 - Goran
1
使用 import Image 替换 from PIL import Image - Wee
出现相同的错误...然后我按照你的方法进行了测试,测试通过了,但是仍然抛出以下错误:.. Exception Location: build/bdist.linux-x86_64/egg/PIL/Image.py in _getdecoder, line 415 - Raja Simon
在selftest.testimage的第76行中出现错误:len(im.tostring()) 引发异常: Traceback (most recent call last): File "./doctest.py", line 499, in _run_examples_inner exec compile(source, "<string>", "single") in globs File "<string>", line 1, in <module> File "/home/ubuntu/.local/lib/python2.7/site-packages/PIL/Image.py", line 697, in tostring "Please call tobytes() instead.") NotImplementedError: tostring()已被删除。请改为调用tobytes()。 - Jithin U. Ahmed
1个项目失败: selftest.testimage中的57个测试之一 测试失败 1个失败。 ***57个测试中有1个失败。 - Jithin U. Ahmed

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接