以Python Imaging Library(PIL)为例,进行安装。限制条件是:

  • 没有写python lib所在路径的权限
  • 服务器jpeg so包不在默认路径,而是/usr/lib64下

如果按照默认方法安装,会报错:IOError: decoder jpeg not available。因为setup.py时没有关联到其依赖的图片库。

1. 下载源代码包,并解压

在http://www.pythonware.com/products/pil/ 选择相应版本,我选择的是Python Imaging Library 1.1.7 Source Kit (all platforms) (November 15, 2009)

wget “http://effbot.org/downloads/Imaging-1.1.7.tar.gz”; tar -xzvf  Imaging-1.1.7.tar.gz; cd Imaging-1.1.7

2. 修改setup.py,使其能够找到libjpeg.so包

# Use None to look for the libraries in well-known library locations.
# Use a string to specify a single directory, for both the library and
# the include files. Use a tuple to specify separate directories:
# (libpath, includepath).

JPEG_ROOT = (“/usr/lib64″, “/usr/include”)

3. 指定路径安装(注意,该路径随意,只要你有读写权限即可)

python setup.py install –home /path/to/your/pythonlib/

关注其最初的output:

*** TKINTER support not available
— JPEG support available
— ZLIB (PNG/ZIP) support available
— FREETYPE2 support available
*** LITTLECMS support not available

4. 将pythonlib路径加入PYTHONPATH,注意要深入到lib/python里

$ tail -1 ~/.bash_profile

export PYTHONPATH=/path/to/your/pythonlib/lib/python/:$PYTHONPATH

Leave a Reply