2010-11-06 72 views
4

背景從PIL setup.py建立一個位:PIL不會導入_imaging C模塊中:「***的_imaging C模塊中未安裝」

-------------------------------------------------------------------- 
PIL 1.1.7 SETUP SUMMARY 
-------------------------------------------------------------------- 
version  1.1.7 
platform  linux2 2.6.2 (release26-maint, Apr 19 2009, 01:58:18) 
       [GCC 4.3.3] 
-------------------------------------------------------------------- 
*** TKINTER support not available 
--- JPEG support available 
--- ZLIB (PNG/ZIP) support available 
--- FREETYPE2 support available 
*** LITTLECMS support not available 
-------------------------------------------------------------------- 

這是的Ubuntu 9.04安裝。

我只需要PIL就可以讓Django上傳和調整各種不同格式的圖像。不幸的是,它目前不能處理JPEG。執行PIL的selftest.py後,想出了這個:

*** The _imaging C module is not installed 

我試圖導入圖像,並使用Python解釋器-v(兩者合作)_imaging ...

>>> from PIL import Image 
import PIL # directory PIL 
# PIL/__init__.pyc matches PIL/__init__.py 
import PIL # precompiled from PIL/__init__.pyc 
# PIL/Image.pyc matches PIL/Image.py 
import PIL.Image # precompiled from PIL/Image.pyc 

[繼續成功相當長的一段]

>>> import _imaging 
dlopen("/usr/local/lib/python2.6/dist-packages/PIL/_imaging.so", 2); 
import _imaging # dynamically loaded from /usr/local/lib/python2.6/dist-packages/PIL/_imaging.so 

使用Python解釋器時,那麼_imaging是可用的,但由於某種原因沒有被進口在其他情況正常。

我一直在尋找這個問題的解決方案,在過去的幾個小時,並沒有任何接近找到一個。我錯過了一些愚蠢明顯的東西嗎?或者有什麼想法,爲什麼它不工作?

在此先感謝!

另外:我知道http://effbot.org/zone/pil-imaging-not-installed.htm,但只是演示錯誤,並沒有提供解決方案。

編輯:我一直在窺探,看來導入_imagingmath是問題。我做了蟒蛇-vv selftest.py看到它被打破了,這是怎麼回事:

dlopen("/usr/local/lib/python2.6/dist-packages/PIL/_imagingmath.so", 2); 
import _imagingmath # dynamically loaded from /usr/local/lib/python2.6/dist-packages/PIL/_imagingmath.so 
*** The _imaging C module is not installed 
# clear __builtin__._ 
[etc. etc. etc.] 

回答

5

看來,在我安裝PIL之前,我沒有安裝libjpeg。因此我安裝了libjpeg-62和libjpeg62-dev,然後重新安裝了PIL。發生

*** The _imaging C module is not installed 

同樣的錯誤,我發現其他網站上提示我強迫從源代碼重建PIL一個潛在的解決方案:

sudo python setup.py build_ext -f 

這扔了信息的幾個有趣的作品有關此錯誤(如果你'也有這個問題)。看來,GCC不正確編制各種文件(我有gcc4.3.3),即如下:

_imaging.c:3017: warning: initialization from incompatible pointer type 
_imaging.c:3077: warning: initialization from incompatible pointer type 
libImaging/Quant.c: In function 'rehash_collide': 
libImaging/Quant.c:154: warning: cast to pointer from integer of different size 

(一切似乎罰款)

我做了一些研究這一點,一些其他網站表明,這是因爲我用來構建PIL的gcc版本與用於構建我正在使用的python.org Python的版本不同。這非常有意義。 Here's the other question I found that suggests this

最後,我嘗試了最後一次安裝,但是這次是從存儲庫,而不是我下載的tar。這似乎解決了這個問題。

sudo apt-get install python-imaging 

雖然我還沒有完全回答了原來的問題,我已經找到一個替代的解決方案,並希望上述信息將能夠幫助任何人在這種情況下,其他人!

0

您尚未安裝的libjpeg庫。這樣做:

sudo apt-get install libjpeg 

並重新運行PIL安裝。

+0

這給我的錯誤:「E:找不到包的libjpeg」。我確實已經安裝了libjpeg62 - 是否相當於? – 2010-11-06 13:03:45

+0

你有libjpeg62-devel嗎? – 2010-11-06 13:25:16

+0

不,我有libjpeg62和libjpeg62-dev。 – 2010-11-06 13:31:05

2

我解決了這個問題通過安裝的libjpeg發展:

sudo apt-get install libjpeg8-dev 

然後完全重新安裝PIL模塊。

(我使用的是一個虛擬的環境,但它應該工作一樣好運行Python作爲標準)