用pil产生验证码出现:ImportError: The _imagingft C module is not installed

这个是由于PIL没有编译freetype导致的
查看 lib/python2.7/site-packages/PIL/
看看 _imagingft.so 是否存在

# 需要先安装jpeg库
wget http://www.ijg.org/files/jpegsrc.v7.tar.gz
tar -zxvf jpegsrc.v7.tar.gz
cd jpeg-7
CC="gcc -arch x86_64"
./configure --enable-shared --enable-static
make
make install
# 然后再安装PIL库
让PIL支持freetype的方法

1、安装freetype开发库
yum install freetype-devel

2、下载源代码http://effbot.org/downloads/Imaging-1.1.7.tar.gz

3、修改setup.py文件
修改

JPEG_ROOT = libinclude("/usr/local")
FREETYPE_ROOT = '/usr/lib64','/usr/include/freetype2/freetype'

4、查看支持项
python setup.py build_ext -i
--- FREETYPE2 support available  注意这一项

5、编译安装
python setup.py install

若上面的设置都失败,则只能拿出下面的杀手锏:

sudo apt-get build-dep python-imaging
sudo ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/
sudo ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/
pip install -U PIL

当现下面的提示时,则说明安装成功了:

--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.3 (default, Apr 10 2012, 22:21:37)
              [GCC 4.6.3]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------

 

 

posted @ 2013-07-30 18:42  网恋被骗5元  阅读(4309)  评论(1编辑  收藏  举报