没有名为_imagingft的模块
我遇到了这个问题:
No module named _imagingft
我已经安装了PIL这个库,但它还是不能正常工作。我用的是OSX系统。
我正在尝试为Django Simple Captcha安装这个模块。
8 个回答
2
感谢一些资源的帮助(具体来源在最后),我整理了以下这个脚本,它对我来说有效,但你可能会有不同的体验。(在运行之前请仔细检查一下。它可能有一些错误,搞得你心烦意乱,甚至可能让你的猫变得毛发凌乱,或者让你的车用上不好的燃料):
#!/bin/bash
pip-2.6 uninstall PIL
# Just in case there's a virtualenv someplace:
pip uninstall PIL
# And forcibly clean up PIL as well
rm -rf /Library/Python/2.6/site-packages/PIL*
if [ ! -d "/usr/X11/include/freetype2" ];then
echo "You need to have XCode installed with the freetype libraries"
exit 1
fi
# Ok we're good to install ...
# Freetype is installed by XCode, so let's link to that for PIL's
# setup.py to know where to find things
ln -s /usr/X11/include/freetype2 /usr/local/include/
ln -s /usr/X11/include/ft2build.h /usr/local/include/
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/libfreetype.dylib
pip-2.6 install PIL
# OR
# pip-2.6 install http://effbot.org/downloads/Imaging-1.1.7.tar.gz
来源:
13
我通过在已有的PIL基础上安装Pillow解决了这个问题:
$ sudo easy_install PIL
$ sudo easy_install Pillow
5
克里斯托弗的建议对我来说非常有效。
具体步骤如下:
卸载现有的Python图像库。
下载并解压源代码版本(可以从这里获取: http://effbot.org/downloads/Imaging-1.1.6.tar.gz)
安装freetype2库(你需要这个库,因为_imagingft可以处理验证码的TrueType字体)。
修改setup.py文件(在解压后的PIL源代码文件夹里),使其与freetype2库匹配(例如,在我的Centos VPS上,我把'FREETYPE_ROOT = None'这一行改成了'FREETYPE_ROOT = "/usr/local/include")。
构建PIL(运行python setup.py build),并确认Freetype2的支持是正常的。
安装PIL(运行python setup.py install)。
安装完成后,你可以通过打开Python控制台并输入'import _imagingft'来验证库是否存在。
如果你使用的是Ubuntu,可以参考以下手册: http://helloworld.infobart.com/compiling-pil-on-ubuntu-natty