Python在OS X上使用错误版本的GCC构建 [英] Python build using wrong version of GCC on OS X

查看:100
本文介绍了Python在OS X上使用错误版本的GCC构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建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_py
运行build_ext
警告:GMP库未找到;不构建Crypto.PublicKey._fastmath。
building'Crypto.Hash.MD2'扩展名
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
无法执行gcc-4.0:没有这样的文件或目录
错误:命令'gcc-4.0'失败,退出状态1
bash-3.2 $
bash-3.2 $
bash-3.2

我使用的是Mac OS X 10.6.7和python 2.6.6,


$ b 编辑:如果我添加CC = gcc-4.2,那么我仍然会收到错误:

  bash-3.2 $ 
bash-3.2 $ export CC = gcc-4.2
bash-3.2 $ python setup.py生成
生成生成
正在运行build_py
正在运行build_ext
警告:未找到GMP库;不构建Crypto.PublicKey._fastmath。
building'Crypto.Hash.MD2'扩展
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
无法执行gcc-4.0:没有这样的文件或目录
错误:命令'gcc-4.0'失败,退出状态1
bash-3.2 $

编辑:看来,使用sudo在这里有所作为。



我尝试使用CC和CXX作为Adam的建议,并且在没有sudo的情况下出现以下错误:

  bash -3.2 $ python setup.py build 
正在运行build
正在运行build_py
正在创建build / lib.macosx-10.3-fat-2.6
正在创建build / lib.macosx-10.3-fat -2.6 /加密
复制lib / Crypto / __ init__.py - > build / lib.macosx-10.3-fat-2.6 / Crypto
复制lib / Crypto / pct_warnings.py - > build / lib.macosx-10.3-fat-2.6 / Crypto
...
警告:未找到GMP库;不构建Crypto.PublicKey._fastmath。
构建'Crypto.Hash.MD2'扩展名
创建构建/ temp.macosx-10.3-fat-2.6
创建构建/ 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:汇编程序(/usr/bin/../libexec/gcc/darwin/ppc/as或/usr/bin/../local/libexec/gcc/darwin/ppc/as)for architecture ppc not安装
安装的汇编程序是:
/usr/bin/../libexec/gcc/darwin/x86_64/as架构x86_64
/usr/bin/../libexec/gcc/darwin / i386 /至于架构i386
lipo:无法打开输入文件:/var/tmp//ccxan625.out(没有这样的文件或目录)
错误:命令'gcc-4.2'失败退出状态1

如果我使用sudo,在尝试使用4.0时出现以下错误:

  bash-3.2 $ sudo python setup.py build 
密码:
正在运行的生成
正在运行build_py
正在运行build_ext
警告:未找到GMP库;不构建Crypto.PublicKey._fastmath。
building'Crypto.Hash.MD2'扩展名
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
无法执行gcc-4.0:没有这样的文件或目录
错误:命令'gcc-4.0'失败,退出状态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编译的,并且是英特尔版本,所以在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
运行build
运行build_py
创建build
创建build / lib.macosx-10.6-universal-2.6
创建build / lib.macosx-10.6 -universal-2.6 / Crypto
复制lib / Crypto / __ init__.py - > build / lib.macosx-10.6-universal-2.6 / Crypto
[...]
正在运行build_ext
警告:未找到GMP库;不构建Crypto.PublicKey._fastmath。
构建'Crypto.Hash.MD2'扩展
创建构建/ temp.macosx-10.6-universal-2.6
创建构建/ 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-W1,-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'扩展名
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安装
正在运行安装
正在运行生成
正在运行build_py
正在运行build_ext
警告:未找到GMP库;不构建Crypto.PublicKey._fastmath。
正在运行install_lib
正在创建/Library/Python/2.6/site-packages/Crypto
[...]
字节编译/Library/Python/2.6/site-packages/ Crypto / pct_warnings.py到pct_warnings.pyc
正在运行install_egg_info
写入/Library/Python/2.6/site-packages/pycrypto-2.3-py2.6.egg-info
$ / usr / bin / python2.6 setup.py测试
运行测试
............................... .................................................. ........... [...]
------------------------------ ----------------------------------------
在42.612s内运行902次测试

OK
$ cd
$ /usr/bin/python2.6
Python 2.6.1(r261:67515,2010年6月24日,21:47:49 )
[GCC 4.2.1(Apple Inc. build 5646)]在darwin
上输入help,copyright,credits或license以获取更多信息。
>>> 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


I am attempting to build the python package pycrypto. OS X has gcc-4.2 installed and not gcc-4.0, but python continues to attempt to use gcc-4.0. How can I get it to use gcc-4.2? Or should I go about this a different way.

I am getting the following error:

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$ 

I am using Mac OS X 10.6.7 with python 2.6.6 and XCode is installed.

EDIT: If I add CC=gcc-4.2, then I still get the error:

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$ 

EDIT: It seems that using sudo makes a difference here.

I tried using both CC and CXX as suggest by Adam, and I get the following error without 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

If I use sudo, I get the following error where it tries to use 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$ 

Does this extra info make it more obvious what is going on and how to fix it? Any idea why the call without sudo is getting that other error?

解决方案

Based on the path shown (/Library/Frameworks/Python.framework/Versions/2.6), it appears you have installed a 32-bit-only Python 2.6, perhaps using a python.org installer. When you build a Python package that includes a C extension module, the Python Distutils included with that Python instance will attempt to use the same version of gcc and the same CPU architectures that that Python was built with. Apparently you have installed the new cutting-edge Xcode 4 which no longer includes gcc-4.0 or ppc support. The Python versions you are using was built with the Xcode 3 tools included with Mac OS X 10.6. You may be able to work around it by overriding the compiler choice with:

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

EDIT:

It looks like that is not going to work for pycrypto; its build is too compex. If you don't mind using the Apple-supplied Python 2.6 in OS X 10.6, this should work:

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

Another option would be to install the 64-bit/32-bit Python 2.7 installer from python.org. That is built with gcc-4.2 and is Intel-only so there shouldn't be any problems when using it with Xcode 4.

UPDATE:

Here are the exact steps I used with Xcode 3. They should work as well with Xcode 4 installed:

$ 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

这篇关于Python在OS X上使用错误版本的GCC构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆