关注小众语言、AI技术,记录、分享技术点滴!

0%

python Image Library安装体验

PIL是python理想的图片处理module,没安装该模块时会提示:ImportError: No module named Image,以下是PIL安装的依赖和步骤

我的环境:CentOS 6.5 / Python2.7

第一步:安装zlib png freetype ** jpeg**

安装zlib:http://zlib.net/zlib-1.2.8.tar.gz

1
2
3
4
5
$ tar -xvzf zlib-1.2.8.tar.gz
$ cd zlib-1.2.8
$ ./configure --prefix=/usr/local
$ make
$ make install

安装png:ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng15/libpng-1.5.23.tar.gz (如果文件不存在就浏览 /src/目录查找一下最新版)

1
2
3
4
5
$ tar -xvzf libpng-1.5.23.tar.gz
$ cd libpng-1.5.23
$ ./configure --prefix=/usr/local
$ make
$ make install

安装freetype:http://nchc.dl.sourceforge.net/project/freetype/freetype2/2.4.7/freetype-2.4.7.tar.gz

1
2
3
4
5
$ tar -xvzf freetype-2.4.7.tar.gz
$ cd freetype-2.4.7/
$ ./configure --prefix=/usr/local
$ make
$ make install

安装jpeg:http://www.ijg.org/files/jpegsrc.v8c.tar.gz

1
2
3
4
5
$ tar -xvzf jpegsrc.v8c.tar.gz
$ cd jpeg-8c/
$ ./configure --prefix=/usr/local
$ make
$ make install

第二步:安装需要的 devel库(该步视情况可忽略)

1
2
3
4
$ yum install libjpeg8-dev
$ yum install libpng12-dev
$ yum install libfreetype6-dev
$ yum install zlib1g-dev

第三步:安装 PIL( Python Imaging Library

安装Image Library:http://effbot.org/downloads/Imaging-1.1.7.tar.gz

1
2
3
4
5
6
7
8
9
10
$ tar -xvzf Imaging-1.1.7.tar.gz
$ cd Imaging-1.1.7/

#修改setup.py文件
vi setup.py

#修改如下:
JPEG_ROOT = "/usr/local/lib"
ZLIB_ROOT = "/usr/local/lib"
FREETYPE_ROOT = "/usr/local/lib"

检查是否支持

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ python setup.py build_ext -i

running build_ext
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.8 (default, Sep 5 2014, 10:24:17)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.

开始安装Image Library

1
2
$ python setup.py build
$ python setup.py install

Python代码验证

1
2
$ python selftest.py
*** The _imaging C module is not installed

ps:
运行python selftest.py提示The _imaging C module is not installed

解决方法,实际根据自己的python PIL路径设置

$ echo ‘/usr/local/lib/python2.7/site-packages/PIL’ >> /etc/ld.so.conf
$ ldconfig

重新python selftest.py,一路安装完成。