2012-05-31 37 views
1

我有一個django應用程序,需要PIL,我一直在得到錯誤,所以我決定在我的託管服務器上玩PIL。virtualenv奇怪的PIL行爲 - Python

PIL安裝在我的虛擬環境中。但是,運行以下時出現錯誤,並且在虛擬環境外運行時出現錯誤。

Python 2.7.3 (default, Apr 16 2012, 15:47:14) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import Image 
>>> im = Image.open('test.png') 
>>> im 
<PngImagePlugin.PngImageFile image mode=RGBA size=28x22 at 0x7F477CFFAE18> 
>>> im.convert('RGB') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/opt/python27/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/Image.py", line 679, in convert 
    self.load() 
    File "/opt/python27/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/ImageFile.py", line 189, in load 
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig) 
    File "/opt/python27/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/Image.py", line 385, in _getdecoder 
    raise IOError("decoder %s not available" % decoder_name) 
IOError: decoder zip not available 
>>> 

回答

4

最有可能你在virtualenv中使用的Python是你自己編譯的,而不是系統的Python--是嗎?如果是這樣,你的問題是在構建Python本身時,zlib的頭文件(.h)沒有安裝在你的系統中。

在構建將在virtualenv上使用的Python時,您必須在Linux中具有「ziplib-devel」(或等價物)包。您可以通過從Python控制檯嘗試import zlib來測試它是否正常工作。

作爲重建Python的替代方法,您可以找到系統的Python zip相關文件,並將它們複製到virtualenv中使用的Python(如果它們是相同的Python版本)。

+0

我能夠在我的virtuaelnv中成功導入zlib – AlexBrand

0

你可以試試Pillow,這是一個重新包裝的PIL,與virtualenv一起播放更好。