python编程用到图像有时会出现
decoder jpeg not available
那是因为没有装jpeg编解码库或者是python的PIL库安装不正确。
出现这种情况最好删掉PIL库(进入python的site-package目录,rm -rf PIL PIL.pth),重新再安装一次。重新安装步骤如下:
一、安装jpeg和zlib库
先用linux发行版的rpm包安装jpeg和zlib库
rpm文件是
libjpeg-devel-6b-37.x86_64.rpm
zlib-devel-1.2.3-3.x86_64.rpm
记下安装到到路径(库路径是/usr/lib64, 头文件路径/usr/include)
二、编译PIL库
下载并解压Imaging-1.1.7.tar.gz
进入解压后的目录,修改setup.py文件把:
JPEG_ROOT = None
ZLIB_ROOT = None
修改为:
JPEG_ROOT = "/usr/lib64", "/usr/include"
ZLIB_ROOT = "/usr/lib64", "/usr/include"
运行
python setup.py build_ext -i
此命令用第一步的jpeg等库生成_imaging.so
如果出现:
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
表示编译成功。可以运行:
python selftest.py
验证。正常的话会出现
--------------------------------------------------------------------
*** TKINTER support not installed
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not installed
*** LITTLECMS support not installed
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.
三、安装与部署
如果上面都正常,运行
python setup.py install
会把PIL模块放到python的package目录(如/usr/lib64/python2.4/site-packages/),同时生成PIL.pth文件