python - Mac OS-X Mountain Lion 上的 GCC-4.2 错误,无法使用 pip/virtualenv 安装某些包

标签 python macos gcc pip osx-mountain-lion

我看到一个非常烦人的错误,我真的不知道如何处理。这似乎很常见,而且我已经尝试了几乎所有我能找到的解决方案,但都无济于事。

我正在尝试使用 pip 安装库。 gevent、psycopg2 和 greenlet 都遇到过这个问题。问题似乎是我的计算机找不到应该与 XCode 4 一起提供的特定 C 编译器:gcc-4.2。这是一个示例(尽管也在 virtualenv 中进行了尝试)。

Last login: Sun Jul 29 23:35:54 on ttys000
*******s-MacBook-Pro:~ ******$ pip install gevent
Downloading/unpacking gevent
  Downloading gevent-0.13.7.tar.gz (288Kb): 288Kb downloaded
  Running setup.py egg_info for package gevent

Downloading/unpacking greenlet (from gevent)
  Downloading greenlet-0.4.0.zip (72Kb): 72Kb downloaded
  Running setup.py egg_info for package greenlet

Installing collected packages: gevent, greenlet
  Running setup.py install for gevent
    building 'gevent.core' extension
    gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c gevent/core.c -o build/temp.macosx-10.6-intel-2.7/gevent/core.o
In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/unicodeobject.h:4,
                 from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:85,
                 from gevent/core.c:4:
/Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
In file included from gevent/core.c:225:
gevent/libevent.h:9:19: error: event.h: No such file or directory
gevent/libevent.h:38:20: error: evhttp.h: No such file or directory
gevent/libevent.h:39:19: error: evdns.h: No such file or directory
gevent/core.c:361: error: field ‘ev’ has incomplete type
gevent/core.c:741: warning: parameter names (without types) in function declaration

....more like this but i'll skip it for now....

copying gevent/wsgi.py -> build/lib.macosx-10.6-intel-2.7/gevent

running build_ext

building 'gevent.core' extension

creating build/temp.macosx-10.6-intel-2.7

creating build/temp.macosx-10.6-intel-2.7/gevent

gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c    gevent/core.c -o build/temp.macosx-10.6-intel-2.7/gevent/core.o

In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/unicodeobject.h:4,

             from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:85,

             from gevent/core.c:4:

/Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory

In file included from gevent/core.c:225:

gevent/libevent.h:9:19: error: event.h: No such file or directory

gevent/libevent.h:38:20: error: evhttp.h: No such file or directory

gevent/libevent.h:39:19: error: evdns.h: No such file or directory

....more like this as well....

gevent/core.c:15559: warning: assignment makes pointer from integer without a cast

gevent/core.c: At top level:

gevent/core.c:21272: error: expected ‘)’ before ‘val’

lipo: can't figure out the architecture type of:    /var/folders/xc/f2mg5kn96kqdr3tj19pgyhs00000gn/T//cckLxkJ2.out

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

Command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c        "import setuptools;__file__='/Users/******/build/gevent/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record   /var/folders/xc/f2mg5kn96kqdr3tj19pgyhs00000gn/T/pip-yA5oWR-record/install-record.txt failed with error code 1 in /Users/******/build/gevent
Storing complete log in /Users/******/.pip/pip.log
***********s-MacBook-Pro:~ ******$ 

你可能会问的事情:

1) 你试过使用 virtualenv 吗?

是的。我尝试像这样符号链接(symbolic link)一个预先存在的 gcc(存在于/usr/bin/目录中):

ln -s /usr/bin/gcc gcc-4.2
ln -s /usr/bin/gcc-4.2 gcc-4.2
ln -s /usr/bin/gcc gcc

这些都不起作用。

2) 您是否尝试重新安装 XCode?

是的。

3) 您是否安装了 XCode 命令行工具?

是的。

4) 你确定你有 gcc 吗?

**********s-MacBook-Pro:~ sanjay$ gcc
i686-apple-darwin11-llvm-gcc-4.2: no input files

5) Python安装?

************s-MacBook-Pro:~ ******$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

关于什么可能是错的以及如何解决它有什么想法吗?

我也试过安装这个:https://github.com/kennethreitz/osx-gcc-installer .我不知道还能尝试什么。对于 unix-y 编码/安装方面的事情,我是个新手,所以如果有什么地方我做得很糟糕,请指出来。

谢谢!

最佳答案

pycrypto 安装在 virtualenv 中无法编译的相同问题。通过发帖者 jiaaro 在此线程中找到了解决方案: https://gist.github.com/3179227#gistcomment-379913

You need to install Xcode 4.4 (from the app store) and then, within xcode open Xcode > Preferences (or press Cmd + ,) then open the downloads tab and install the Command Line Tools.

在 Mac OSx Mountain Lion 10.8 上,我使用命令行工具安装了 xCode 4.3。我对 xCode 4.4 进行了更新,但仍然无法正常工作。 Xcode 显然不会自动下载新的命令行工具,即使您已经安装了它们。正如 jiaaro 的帖子所述,您必须再次明确下载命令行工具。

gcc 的当前版本如下,并且在 virtualenv 中为我成功执行了 sudo pip install packages,无需符号链接(symbolic link)。

gcc

i686-apple-darwin11-llvm-gcc-4.2

关于python - Mac OS-X Mountain Lion 上的 GCC-4.2 错误,无法使用 pip/virtualenv 安装某些包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11716107/

相关文章:

python - 在搜索结果中包含空值

Java Mac appbundle 资源路径

c - 关于不正确的打包编译指示的警告

python - 系列的真值是不明确的。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()

python - 是否有可能对 Django 进行反向修补?

python - 在 Python 中从十六进制解压到双倍

python - 在 OSX 上为 virtualenv 设置 Python 32 位和 64 位模式

html - iframe 滚动条在 Mac 上的 Chrome 中消失

c++ - gcc 和 g++ 错误 : error trying to exec 'cc1plus' : execvp: No such file or directory

c - 具有相同名称和类型的两个变量,在两个不同的 .c 文件中,使用 gcc 编译