安装PIL的坑

系统 1164 0

今天在centos中使用pip安装PIL死活不成功,报错:

        Could not find a version that satisfies the requirement PIL (from versions: )

  Some externally hosted files were ignored as access to them may be unreliable (use --allow-external PIL to allow).

  No matching distribution found for PIL


    

但是使用pip search PIL查找,源中确实有该包:

      PIL                                  - Python Imaging Library


    

 

google之,得到如下办法(http://stackoverflow.com/questions/21242107/pip-install-pil-dont-install-into-virtualenv):

      sudo pip install PIL --allow-external PIL --allow-unverified PIL


    

果然成功了。

 

但是程序运行时又报错:

      font = ImageFont.truetype(os.path.join("fonts",font_type), font_size)
      
ImportError: The _imagingft C module is not installed

似乎是没有安装truetype扩展之类的。那就安装吧(http://stackoverflow.com/questions/4011705/python-the-imagingft-c-module-is-not-installed):

      sudo yum install freetype-devel


    

 

然后卸载、重新安装PIL

      sudo pip uninstall PIL

sudo pip install PIL --allow-external PIL --allow-unverified PIL


    

终于搞定了  

 

 

 

PS:之前还尝试过从官网下载PIL源码自己编译安装:

(参照:http://www.cnblogs.com/free--coder/archive/2012/09/12/2681361.html)

1.下载源码并解压:

      wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz

tar -xzvf Imaging-1.1.7.tar.gz 


    

2.编译安装(注意要root权限):

      python setup.py build

python setup.py install  


    

 

安装倒是成功了,但是python脚本运行时报错:

      /usr/lib64/python2.7/site-packages/PIL/Image.py:81: RuntimeWarning: The _imaging extension was built for another  version of Pillow or PIL

  warnings.warn(str(v), RuntimeWarning)

Traceback (most recent call last):

  File "captcha.py", line 3, in <module>

    import Image, ImageDraw, ImageFont, ImageFilter

  File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 65, in <module>

    raise ImportError("The _imaging extension was built for another "

ImportError: The _imaging extension was built for another  version of Pillow or PIL


    

似乎版本不对。。。。。

放弃了

安装PIL的坑


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论