2013-04-03 104 views
0

當我安裝PIL(或枕頭)時,不會安裝_imaging C模塊。構建PIL的_imaging擴展時出現gcc-4.0錯誤

這是一個常見錯誤,並且看到ApPeL's play-by-play solution大多數人發現有幫助。不幸的是,當我運行sudo python setup.py install,我得到以下錯誤:

running install 
running build 
running build_py 
running build_ext 
--- using frameworks at /System/Library/Frameworks 
building '_imaging' extension 
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -DHAVE_LIBJPEG -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/local/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.3-fat-2.7/_imaging.o 
unable to execute gcc-4.0: No such file or directory 
error: command 'gcc-4.0' failed with exit status 1 

當我運行shell蟒蛇,並嘗試導入的模塊,我得到這些導入錯誤:

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ python 
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import PIL 
>>> import Image 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named Image 
>>> import _imaging 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named _imaging 

我以前有類似的錯誤,並且Ned Deily has been kind enough to provide solutions。我相信我現在的問題可能被鏈接到這個先前的問題:

OSX: error when installing Python packages(包括此作爲參考)

下面是一些其他潛在有用的信息:

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ python 
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ gcc 
i686-apple-darwin11-llvm-gcc-4.2: no input files 

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ which python 
/Library/Frameworks/Python.framework/Versions/2.7/bin/python 

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ echo $PATH 
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin 

我對gcc,Xcode或PIL不是很熟悉。所以,如果您不介意,請提供詳細的回覆,以便我瞭解如何處理您的解決方案。另外,讓我知道我是否可以提供更多細節,並將其編輯爲問題。


編輯:

我已經安裝了pillow與點子,由MattDMo的建議,現在Image成功導入,但_imaging沒有(我相信C擴展不由被正確編譯GCC我的機器上,見上文):

Santiagos-MacBook-Air:riotry_mobile sgarza621$ python 
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import Image 
>>> import _imaging 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart 
    Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_imaging.so 
    Expected in: dynamic lookup 

我使用PIL來處理一個Django的web應用程序的圖像,我得到以下錯誤,當我嘗試uploa d通過PIL用於處理的形式的圖像:

The _imaging C module is not installed 

第二個編輯:

這裏的更多信息,與蟒蛇和gcc,我希望將闡明這個問題光:

$ which python 
/Library/Frameworks/Python.framework/Versions/2.7/bin/python 
$ /usr/bin/python -c 'import sys;print(sys.version)' 
2.7.2 (default, Jun 16 2012, 12:38:40) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] 
$ /usr/bin/python2.7 -c 'import sys;print(sys.version)' 
2.7.2 (default, Jun 16 2012, 12:38:40) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] 

回答

0

哇。我希望這能幫助那些未來有同樣問題的人,因爲這是殘酷的。

解決的辦法是爲Mac安裝python.org 64-bit/32-bit installer,如Ned Deily's answer中概述的「…can't figure out the architecture type of…」 problem when compiling Python C-extension with gcc

首先,我確定默認的python是這個新的python(只需在shell中運行python)。

然後,我重新安裝了pip,並跑了pip install PIL。那就做到了!

只是爲了確保,我在外殼打開了Python和進口三個模塊:

>>> import PIL 
>>> import Image 
>>> import _imaging 

他們都(最終)進口沒有錯誤。

+1

很高興您的工作能夠順利進行。在OS X上安裝PIL還有其他可能的缺陷.OS X不附帶支持JPEG的庫PIL需求;如果你需要的話,你可能還需要編譯和安裝libjpeg並重建PIL。看來您的原始問題是由Python 2.7.3帶有Xcode 4(OS X 10.7或10.8)上的python.org OS X 32位安裝程序引起的。如果不進行調整,該組合效果不佳。您發現使用2.7.3的64位/ 32位安裝程序效果更好。 (2.7.4即將發佈的效果更好)。 – 2013-04-04 03:52:59

+1

但是,因爲PIL需要額外的第三方庫以提供全部功能,所以我強烈建議您使用OS X的開放源碼軟件包分銷商(MacPorts,Homebrew或Fink)來安裝您需要的所有軟件,包括Django,Python ,PIL,MySQL或PostgreSQL。從長遠來看,您幾乎可以肯定的爲自己節省大量時間和頭痛,因爲他們已經想出瞭如何輕鬆安裝,更新和刪除數百個應該一起玩的組件。 – 2013-04-04 03:58:37

2

許多如果不是所有的你的問題(希望)可以通過使用Pillow,而不是解決。 PIL開發剛剛停頓了一段時間,不幸的是代碼並沒有以任何方式向前兼容,所以隨着編譯器和Python的成熟,錯誤悄然而至。枕頭叉穩定,積極開發並且非常普遍,所以你可以安心使用它。 2.0版有一些增強功能,包括Python 3支持。不過,您必須使用from PIL import Image而不是import Image。祝你好運!

+0

感謝您的回答,請檢查編輯 – sgarza62 2013-04-04 01:16:44

相關問題