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開發上。
好了,卸載先前的官方PIL,安裝Pillow後,所有問題都解決了。 然後又出問題了
這次是 cannot identify image file 'tmp_20.png'
這個是image庫進行load的時候出問題,然後其實很簡單就是
from PIL import Image
替換掉 import Image就可以了