1

我正在尝试在 virtualenv 中使用 Scrapy,这也需要安装 twisted。我pip install Scrapy没有问题,但是当我尝试时pip install twisted,我在输出中多次收到以下错误:

unable to execute gcc-4.0: No such file or directory

error: command 'gcc-4.0' failed with exit status 1

我之前尝试在我的实际系统上安装 python 包时遇到了类似的问题,这就是我首先开始使用 virtualenv 的原因。这是我的环境中安装的 python 版本的问题吗?这是我目前拥有的:

Django          - 1.5          - active 
Python          - 2.7.3        - active development (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload)
Scrapy          - 0.16.4       - active 
pip             - 1.2.1        - active 
setuptools      - 0.6c11       - active 
wsgiref         - 0.1.2        - active development (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7)
yolk            - 0.4.3        - active

为了检查我gcc在命令行输入了哪个版本的 gcc 并得到了

i686-apple-darwin11-llvm-gcc-4.2: no input files

export CC=gcc-4.2我在运行之前尝试过pip install twisted,我得到了:

llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory

lipo: can't figure out the architecture type of: /var/folders/s8/d0f65gc93nbchdk52g2cg5f80000gn/T//ccWQa7cJ.out

error: command 'gcc-4.2' failed with exit status 255

它在我看来有点像它正在寻找powerpc-apple-darwin11-llvm-gcc-4.2,而我上面的内容是i686-apple-darwin11-llvm-gcc-4.2——这些是不同的,因此会导致问题吗?

为了提供更多背景信息,我很久以前从 Python.org 安装程序安装了 Python 2.7,然后从 Snow Leopard 直接升级到 Mountain Lion。如果我只是在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

所以我猜这意味着我正在使用 Apple 的 Python?它是用 gcc-4.0.1 构建的?所以如果是这样的话,我不应该不需要这样做export CC=gcc-4.2吗?还是我需要这样做并切换到 Python.org 版本的 Python?(如果是后者,我该怎么做?)

更新: 我尝试了此解决方案来切换 Python 版本,但没有奏效。

更新: 我设法使用sudo port select --set python python27命令切换 Python 版本(在我的 virtualenv 之外),但这并没有解决问题,即使我现在显示:

Python 2.7.3 (default, Nov 17 2012, 19:54:34) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin

当我python在命令行输入时。

更新:我还发现这个问题的解决方案似乎与我遇到的问题几乎完全相同,但我已经升级到 XCode 4.6 并且肯定按照上述解决方案中的描述安装了命令行工具(首选项>下载选项卡>安装命令行工具)。我也安装了 XCode 3.2.6,但是——有没有可能导致我的问题?

4

1 回答 1

1

你试过CC="$(type -p clang)" pip install twisted吗?你不一定需要用来gcc编译 Twisted 的扩展;相反,选择clang可能会清除似乎困扰您的gcc安装的任何奇怪问题。

如果这不起作用,我建议卸载任何 Python.org 版本的 Python,然后可能重新安装 OS 和 Xcode,因为看起来某些东西可能损坏了您的系统 Python 安装。我不知道对powerpc东西的引用是如何持续到 Mountain Lion 中的,因为 Lion 取消了对 ppc 的支持。

于 2013-03-05T00:36:19.617 回答