簡體   English   中英

為PIL構建_imaging擴展時出現gcc-4.0錯誤

[英]gcc-4.0 error when building _imaging extension for PIL

當我安裝PIL(或枕頭)時,_imaging C模塊不會安裝。

這是一個常見的錯誤,並且已經看到了ApPeL的逐個播放解決方案 ,大多數人發現這些解決方案很有幫助。 不幸的是,當我運行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中運行python,並嘗試導入模塊時,我收到這些導入錯誤:

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非常友好地提供解決方案 我相信我目前的問題可能與之前的問題有關:

OSX:安裝Python包時出錯 (包括此參考)

以下是其他一些可能有用的信息:

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我不熟悉這些細節。 因此,如果您不介意,請提供詳細的回復,以便我了解如何對您的解決方案采取行動。 另外,如果我能提供更多詳細信息,請告訴我,我會將其編輯到問題中。


編輯:

我已經按照MattDMo的建議安裝了pip pillowImage現在導入成功,但是_imaging沒有(我相信我的機器上的gcc沒有正確編譯c擴展,見上文):

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應用程序上處理圖像,當我嘗試通過表單上傳圖像以供PIL處理時,我收到以下錯誤:

The _imaging C module is not installed

第二次編輯:

這里有更多關於python和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)]

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

哇。 我希望這可以幫助將來遇到同樣問題的人,因為那是殘酷的。

解決方案是python.org 64-bit/32-bit installer適用於Mac的python.org 64-bit/32-bit installer ,如Ned Deily 在編譯Python C-extension時問題“...無法弄清楚......的體系結構類型”問題中所述。 gcc

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

然后,我重新安裝了pip ,然后運行pip install PIL 就這樣做了!

為了確保,我在shell中打開了python,並導入了三個模塊:

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

所有這些(最后)導入沒有錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM