10

我知道这个问题看起来像是重复的,但我已经遵循了许多关于如何正确安装 PIL 的在线说明,但没有一个有效。

我已经尝试了所有方法:Python Image Library failed with message "decoder JPEG not available" - PIL没有成功。

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

即使在为 .so libjpeg 文件符号链接到 /usr/lib 之后,也没有任何效果。

有任何想法吗?谢谢你。

4

1 回答 1

20

你可以试试这个:

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.

恭喜!!

于 2013-11-20T09:06:18.273 回答