python Image库 出错

来源:互联网 发布:哈登 nba数据 编辑:程序博客网 时间:2024/06/05 07:37

False decoder zip not available

IOError: cannot identify image file 'tmp_20.png'

在老大的注视下,问题一个接一个出现,然后虽然解决了,感觉不爽啊

首先问题是

--------------------------------------------------------------------PIL 1.1.7 SETUP SUMMARY--------------------------------------------------------------------version       1.1.7platform      linux2 2.7.5+ (default, Sep 19 2013, 13:48:49)              [GCC 4.8.1]--------------------------------------------------------------------*** TKINTER support not available*** JPEG support not available*** ZLIB (PNG/ZIP) support not available*** FREETYPE2 support not available*** LITTLECMS support not available--------------------------------------------------------------------

我保存成png文件不行,提示False decoder zip not available

在windows下运行的好好的,但是linux下就是不行,后来终于发现原来是我windows下不是用的PIL,而是PILLOW

看到这一片文章才发现http://wangye.org/blog/archives/752/

转载:

配置的Debian Web服务器,通过virtualenv构建了Pyramid项目,大部分代码运行挺正常,到一个验证码程序时出错了,检查日志得到如下Python异常:

ImportError: No module named PIL

但是我PIL明明是通过easy_install直接安装的啊,求助于网络找到了这么一篇解决方案《The problem with installing PIL using virtualenv or buildout》,原文的意思是在pypi上的PIL版本不兼容于setuptools,所以不能被easy_install正常安装,必须指定url安装兼容版本,比如如下命令:

pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

经过这么一折腾,确实测试下来import PIL不会报错了,但是原程序依旧不能正常运行,继续检查日志后得到下面的异常:

ImportError: The _imagingft C module is not installed

搜索了网络,大多是编译安装PIL时,系统缺少库文件导致的,通过下面的命令安装可能的包或者库文件:

sudo apt-get install libjpeg libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev

然后重新编译下载PIL,结果在这过程中提示如下警告:

--------------------------------------------------------------------*** TKINTER support not available (Tcl/Tk 8.4 libraries needed)*** JPEG support not available*** ZLIB (PNG/ZIP) support not available*** FREETYPE2 support not available--------------------------------------------------------------------To add a missing option, make sure you have the requiredlibrary, and set the corresponding ROOT variable in thesetup.py script.

所有的必须的库仍然提示support not available,说明刚才的安装预先库的办法是没有用的,纠结了。

搜索了网络,大多是针对Ubuntu的解决方案,不过功夫不负有心人,还是让我找到了Debian下的解决办法《PIL zip jpeg decoders not working on runtime but work on install/selftest》,现在分享出来:

其实最简单的办法就是先用命令pip uninstall PIL卸载已有的PIL,然后安装PIL的fork版本Pillow,这是一个“友好”(friendly)的PIL版本,由Plone社区维护,主要用于Web开发上。

pip install pillow

好了,卸载先前的官方PIL,安装Pillow后,所有问题都解决了!

然后又出问题了

这次是 cannot identify image file 'tmp_20.png'

这个是image库进行load的时候出问题,然后其实很简单就是

from PIL import Image
替换掉 import Image就可以了

0 0
原创粉丝点击