【问题标题】:Error compiling coverage.py on MacOSX在 MacOSX 上编译 coverage.py 时出错
【发布时间】:2011-04-26 16:56:42
【问题描述】:

我尝试在运行当前 Mac OS X 10.6.7 的 MacBook 上安装 coverage 3.4。这是我得到的错误:

$ easy_install coverage
install_dir /Users/jammon/workspace/myproject/lib/python2.7/site-packages/
Searching for coverage
Reading http://pypi.python.org/simple/coverage/
Reading http://nedbatchelder.com/code/modules/coverage.html
Reading http://nedbatchelder.com/code/coverage
Reading http://nedbatchelder.com/code/coverage/3.4b1
Reading http://nedbatchelder.com/code/coverage/3.4b2
Best match: coverage 3.4
Downloading http://pypi.python.org/packages/source/c/coverage/coverage-3.4.tar.gz#md5=46782809578c8fd29912c124d2420842
Processing coverage-3.4.tar.gz
Running coverage-3.4/setup.py -q bdist_egg --dist-dir /var/folders/10/10P5vwX-Ghmkg8s25PMr3E+++TI/-Tmp-/easy_install-UcskZB/coverage-3.4/egg-dist-tmp-QCs3YS
no previously-included directories found matching 'test'
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 coverage/tracer.c:3:
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
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 coverage/tracer.c:3:
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
lipo: can't figure out the architecture type of: /var/folders/10/10P5vwX-Ghmkg8s25PMr3E+++TI/-Tmp-//ccAYGjpc.out
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1

任何人都可以从中理解吗?我只是不明白出了什么问题。或者我该如何解决它。
非常感谢任何帮助。

更新:
在 Ned 发表评论后,我尝试使用 easy_install -vv coverage;结果并没有太大的不同:

...
creating build/temp.macosx-10.3-fat-2.7/coverage
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c coverage/tracer.c -o build/temp.macosx-10.3-fat-2.7/coverage/tracer.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 coverage/tracer.c:3:
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
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 coverage/tracer.c:3:
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
lipo: can't figure out the architecture type of: /var/folders/10/10P5vwX-Ghmkg8s25PMr3E+++TI/-Tmp-//ccZQsHOd.out
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1

据我所知,我以标准方式从源代码编译 python,它不是二进制发行版。我在有和没有virtualenv的情况下都试过了。

【问题讨论】:

  • 这很奇怪。安装这个应该没有问题。尝试使用easy_install -vv coverage 再次运行并报告整个gcc 命令。您的 10.4u SDK可能有问题。您可以尝试从 Xcode 3 安装程序重新安装。

标签: python macos installation compiler-errors coverage.py


【解决方案1】:

最新版本的 XCode 删除了对编译到旧 PowerPC (PPC) 架构的支持。不幸的是,Mac 上的 Python 通常仍会尝试为 PPC 和 x86 构建 C 扩展。要解决此问题,请在“setup.py install”或“easy_install”等命令前加上 ARCHFLAGS 设置,该设置仅包含您要为其构建的架构:

ARCHFLAGS="-arch i386 -arch x86_64" easy_install coverage

【讨论】:

  • 这听起来确实像解决方案;但不幸的是,我仍然遇到同样的错误。我真的需要一些时间来研究问题的原因。还是谢谢。
  • 你还有gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c coverage/tracer.c -o build/temp.macosx-10.3-fat-2.7/coverage/tracer.o -arch ppc 在中间吗?这是不好的部分。
  • 这对我有用,在 Mac OS X 10.8(山狮)上编译最新版本的 lxml (2.3.5)。
【解决方案2】:

或者,您可以use ActivePython 来避免需要compile things yourself

$ pypm install coverage
The following packages will be installed into "~/Library/Python/2.7" (2.7):
 coverage-3.4
Get: [pypm-free.activestate.com] coverage 3.4
Installing coverage-3.4                                  
Fixing script ~/Library/Python/2.7/bin/coverage
$

【讨论】:

    【解决方案3】:

    经过大量谷歌搜索后,我在 this blogpost and the comments 中找到了一个对我有用的解决方案:我删除了 /Developer/SDKs/MacOSX10.4u.sdk,然后安装覆盖(和显示相同问题的报告实验室)就可以了正如预期的那样。

    据我了解,在某些版本的 gcc 中对 stdarg.h 的处理发生了变化,导致了所描述的问题。

    【讨论】: