簡體   English   中英

在OS X上使用錯誤版本的GCC構建Python

[英]Python build using wrong version of GCC on OS X

我正在嘗試構建python包pycrypto。 OS X安裝了gcc-4.2而不是gcc-4.0,但是python繼續嘗試使用gcc-4.0。 如何才能使用gcc-4.2? 或者我應該采取不同的方式。

我收到以下錯誤:

bash-3.2$ 
bash-3.2$ sudo python setup.py build
running build
running build_py
running build_ext
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash.MD2' extension
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/MD2.c -o build/temp.macosx-10.3-fat-2.6/src/MD2.o
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1
bash-3.2$ 
bash-3.2$ 
bash-3.2$ 

我正在使用帶有python 2.6.6的Mac OS X 10.6.7並安裝了XCode。

編輯:如果我添加CC = gcc-4.2,那么我仍然得到錯誤:

bash-3.2$ 
bash-3.2$ export CC=gcc-4.2
bash-3.2$ python setup.py build
running build
running build_py
running build_ext
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash.MD2' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -std=c99 -O3 -fomit-frame-pointer -arch i386 -arch x86_64 -Isrc/ -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/MD2.c -o build/temp.macosx-10.3-intel-2.6/src/MD2.o
gcc-4.0 -g -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 build/temp.macosx-10.3-intel-2.6/src/MD2.o -o build/lib.macosx-10.3-intel-2.6/Crypto/Hash/MD2.so
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1
bash-3.2$ 

編輯:似乎使用sudo在這里有所作為。

我嘗試使用CC和CXX作為Adam的建議,沒有sudo我得到以下錯誤:

bash-3.2$ python setup.py build
running build
running build_py
creating build/lib.macosx-10.3-fat-2.6
creating build/lib.macosx-10.3-fat-2.6/Crypto
copying lib/Crypto/__init__.py -> build/lib.macosx-10.3-fat-2.6/Crypto
copying lib/Crypto/pct_warnings.py -> build/lib.macosx-10.3-fat-2.6/Crypto
...
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash.MD2' extension
creating build/temp.macosx-10.3-fat-2.6
creating build/temp.macosx-10.3-fat-2.6/src
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/MD2.c -o build/temp.macosx-10.3-fat-2.6/src/MD2.o
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
lipo: can't open input file: /var/tmp//ccxan625.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1

如果我使用sudo,我會嘗試使用4.0時出現以下錯誤:

bash-3.2$ sudo python setup.py build
Password:
running build
running build_py
running build_ext
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash.MD2' extension
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/MD2.c -o build/temp.macosx-10.3-fat-2.6/src/MD2.o
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1
bash-3.2$ 
bash-3.2$ 

這些額外的信息是否使得更明顯的是什么以及如何解決它? 知道為什么沒有sudo的調用會得到其他錯誤嗎?

根據顯示的路徑( /Library/Frameworks/Python.framework/Versions/2.6 ),您可能已經安裝了一個32位的Python 2.6,可能使用的是python.org安裝程序。 當您構建包含C擴展模塊的Python包時,該Python實例中包含的Python Distutils將嘗試使用相同版本的gcc以及與之構建Python相同的CPU體系結構。 顯然你已經安裝了新的尖端Xcode 4,它不再包含gcc-4.0或ppc支持。 您使用的Python版本是使用Mac OS X 10.6附帶的Xcode 3工具構建的。 可以通過覆蓋編譯器選項來解決它:

export CC=gcc-4.2
python setup.py build
sudo python setup.py install

編輯:

看起來這對pycrypto ; 它的構建過於復雜。 如果您不介意在OS X 10.6中使用Apple提供的Python 2.6,這應該可以:

export ARCHFLAGS='-arch i386 -arch x86_64'
/usr/bin/python2.6 setup.py build

另一種選擇是從python.org安裝64位/ 32位Python 2.7安裝程序 它是用gcc-4.2構建的,並且僅支持Intel,因此在與Xcode 4一起使用時應該沒有任何問題。

更新:

以下是我與Xcode 3一起使用的確切步驟。它們應該與安裝Xcode 4一起使用:

$ mkdir p
$ cd p
$ curl -O http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.3.tar.gz
$ tar xf pycrypto-2.3.tar.gz 
$ cd pycrypto-2.3/
$ export ARCHFLAGS='-arch i386 -arch x86_64'
$ /usr/bin/python2.6 setup.py build
running build
running build_py
creating build
creating build/lib.macosx-10.6-universal-2.6
creating build/lib.macosx-10.6-universal-2.6/Crypto
copying lib/Crypto/__init__.py -> build/lib.macosx-10.6-universal-2.6/Crypto
[...]
running build_ext
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash.MD2' extension
creating build/temp.macosx-10.6-universal-2.6
creating build/temp.macosx-10.6-universal-2.6/src
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -fwrapv -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -std=c99 -O3 -fomit-frame-pointer -arch i386 -arch x86_64 -Isrc/ -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/MD2.c -o build/temp.macosx-10.6-universal-2.6/src/MD2.o
gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 build/temp.macosx-10.6-universal-2.6/src/MD2.o -o build/lib.macosx-10.6-universal-2.6/Crypto/Hash/MD2.so
[...]
building 'Crypto.Util._counter' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -fwrapv -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -std=c99 -O3 -fomit-frame-pointer -arch i386 -arch x86_64 -Isrc/ -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/_counter.c -o build/temp.macosx-10.6-universal-2.6/src/_counter.o
gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 build/temp.macosx-10.6-universal-2.6/src/_counter.o -o build/lib.macosx-10.6-universal-2.6/Crypto/Util/_counter.so
$ /usr/bin/python2.6 setup.py install
running install
running build
running build_py
running build_ext
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
running install_lib
creating /Library/Python/2.6/site-packages/Crypto
[...]
byte-compiling /Library/Python/2.6/site-packages/Crypto/pct_warnings.py to pct_warnings.pyc
running install_egg_info
Writing /Library/Python/2.6/site-packages/pycrypto-2.3-py2.6.egg-info
$ /usr/bin/python2.6 setup.py test
running test
............................................................................................[...]
----------------------------------------------------------------------
Ran 902 tests in 42.612s

OK
$ cd 
$ /usr/bin/python2.6
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from Crypto.Hash import MD5
>>> m = MD5.new()
>>> m.update('abc')
>>> m.digest()
'\x90\x01P\x98<\xd2O\xb0\xd6\x96?}(\xe1\x7fr'
>>> m.hexdigest()
'900150983cd24fb0d6963f7d28e17f72'
>>> ^D

順便說一句,這是一個distutils問題,Python本身並沒有編譯任何東西。

正如您所發現的,您可以使用CC環境變量覆蓋編譯器。 您可以覆蓋與CXX環境變量一起使用的鏈接器。 我也想知道為什么distutils這樣做,但它確實如此。

專注於這個錯誤:

unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1

編譯器正確地告訴你問題是什么。 gcc-4.0 (和gcc-4.2 )不在您的PATH 提示: which gcc-4.2 ,例如:

% which gcc-4.2
/usr/bin/gcc-4.2

假設你的位置在同一個位置,我不確定為什么/usr/bin不在你的PATH ,但是你有它!

找出你的PATH究竟是什么:

% echo $PATH
/opt/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/bin/X11:/sw/bin:/sw/sbin

修復你的道路,你將走上你的啟蒙之路。

暫無
暫無

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

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