2013-03-06 65 views
10

我試圖得到樣品heatmap.py運行: http://jjguy.com/heatmap/「IO錯誤:解碼壓縮不可用」:Ubuntu的Python的PIL

#image.py 
import heatmap 
import random 

if __name__ == "__main__":  
    pts = [] 
    for x in range(400): 
     pts.append((random.random(), random.random())) 

    print "Processing %d points..." % len(pts) 

    hm = heatmap.Heatmap() 
    img = hm.heatmap(pts) 
    img.save("classic.png") 

,我得到這個錯誤:

Processing 400 points... 
Traceback (most recent call last): 
    File "/home/ec2usr/workspace/image/image.py", line 14, in <module> 
    img.save("classic.png") 
    File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1437, in save 
    save_handler(self, fp, filename) 
    File "/usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.py", line 572, in _save 
    ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)]) 
    File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 481, in _save 
    e = Image._getencoder(im.mode, e, a, im.encoderconfig) 
    File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 399, in _getencoder 
    raise IOError("encoder %s not available" % encoder_name) 
IOError: encoder zip not available 

在Ubuntu 12(64位)系統上使用Eclipse 2.7進行工作。

我在/ usr/lib和/ usr/lib/x86_64-linux-gnu中找到libz.so /很好。我已經嘗試了這些解決方案,而結果:

PIL says it has "support available" but still gives IOError when saving files

About the PIL Error -- IOError: decoder zip not available

IOError: "decoder zip not available" using matplotlib PNG in ReportLab on Linux, works on Windows

http://www.foxhop.net/ubuntu-python-easy_install-pil-does-not-install-zlib-support

我一直在拉我的頭髮在這幾天,大大感謝任何人的幫助!

從蟒成像安裝日誌:從安裝

[email protected]:/usr/lib$ sudo apt-get install python-imaging 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
The following packages were automatically installed and are no longer required: 
    account-plugin-identica account-plugin-twitter gir1.2-messagingmenu-1.0 
    hplip-data libgtkspell-3-0 libqt4-designer libqt4-help libqt4-scripttools 
    libqt4-svg libqt4-test libqtassistantclient4 libsane-hpaio 
    linux-headers-3.5.0-21 linux-headers-3.5.0-21-generic python-debtagshw 
    python-lxml python-pexpect python-piston-mini-client python-qt4 
    python-renderpm python-reportlab python-reportlab-accel python-sip 
    software-center-aptdaemon-plugins ubuntu-extras-keyring 
Use 'apt-get autoremove' to remove them. 
Suggested packages: 
    python-imaging-doc python-imaging-dbg 
The following NEW packages will be installed: 
    python-imaging 
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. 
Need to get 0 B/294 kB of archives. 
After this operation, 996 kB of additional disk space will be used. 
Selecting previously unselected package python-imaging. 
(Reading database ... 189302 files and directories currently installed.) 
Unpacking python-imaging (from .../python-imaging_1.1.7-4build1_amd64.deb) ... 
Setting up python-imaging (1.1.7-4build1) ... 
[email protected]:/usr/lib$ 

日誌(Python從成像安裝setup.py):

PIL 1.1.7 SETUP SUMMARY 
-------------------------------------------------------------------- 
version  1.1.7 
platform  linux2 2.7.3 (default, Sep 26 2012, 21:51:14) 
       [GCC 4.7.2] 
-------------------------------------------------------------------- 
--- TKINTER support available 
*** JPEG support not available 
--- ZLIB (PNG/ZIP) support available 
*** FREETYPE2 support not available 
*** LITTLECMS support not available 

selftest.py:

-------------------------------------------------------------------- 
PIL 1.1.7 TEST SUMMARY 
-------------------------------------------------------------------- 
Python modules loaded from ./PIL 
Binary modules loaded from /usr/local/lib/python2.7/dist-packages 
-------------------------------------------------------------------- 
*** PIL CORE support not installed 
*** TKINTER support not installed 
--- JPEG support ok 
--- ZLIB (PNG/ZIP) support ok 
*** FREETYPE2 support not installed 
*** LITTLECMS support not installed 
-------------------------------------------------------------------- 
+0

你有'libz.so'那裏,當你安裝PIL? – wRAR 2013-03-06 21:25:54

+0

我相信是這樣,但是我之後也用sudo apt-get build-dep python-imaging重新編寫了PIL蛋,以防萬一。 – cmacdona101 2013-03-06 21:38:45

+0

更新:.tif工作正常; PNG和JPG不起作用。 – cmacdona101 2013-03-06 21:48:37

回答

9

我剛剛遇到了一個類似的問題,因爲有PIL(通過python pip安裝程序安裝)和python-ima通過apt-get安裝的ging軟件包。當我從pip中移除了爲我解決它的額外版本時。

如果您從源安裝PIL或使用pip,那麼您可能會遇到同樣的問題。

當我建立PIL時,我還發現我必須將庫鏈接到/ usr/lib。這可能會解決上面日誌中不支持的消息。

sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib 
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib 
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib 
7

我記得在與64位系統上安裝PIL時Kris做的完全一樣的解決方案。

但是現在我會推薦使用枕頭(pip安裝枕頭)而不是PIL。 Pillow只是PIL的一個分支,更頻繁的發佈和更少的問題,比如你正在經歷的問題。

如果你在Ubuntu上我認爲你需要的zlib1g-dev的和的libjpeg-dev的安裝之前安裝PIL /枕頭,讓你獲得內置JPEG/PNG支持。

+0

在此處確認您需要在安裝PIL/Pillow之前安裝依賴項,以便安裝過程執行正確的編譯步驟。 – 2013-10-17 01:30:04

+0

這對我來說是正確的答案,它可以在Ubuntu 12.04和14.04上使用python 2.7和3.4 – ThatAintWorking 2014-05-02 23:38:59

1

即使我是PIL到目前爲止,我在Ubuntu 12上解決了這個問題。04用:

pip uninstall PIL 
pip install PIL 
2

這工作完全適合我:

apt-get install libjpeg62 libjpeg62-dev zlib1g-dev libfreetype6 libfreetype6-dev 

在x86_64的:

ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib 
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib 
ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib 

在i386的:

ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/ 
ln -s /usr/lib/i386-linux-gnu/libfreetype.so.6 /usr/lib/ 
ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/ 


pip install -U PIL --allow-external PIL --allow-unverified PIL 
pip install -I pillow