在MacOSX上编译coverage.py时出错

2 投票
3 回答
1649 浏览
提问于 2025-04-16 16:27

我在我的MacBook上安装coverage 3.4,系统是当前的Mac OS X 10.6.7。结果出现了这个错误:

$ 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

3 个回答

0

经过大量的搜索,我在这个博客和评论中找到了一个对我有效的解决办法:我删除了/Developer/SDKs/MacOSX10.4u.sdk,然后安装coverage(还有reportlab,它也出现了同样的问题)就顺利完成了。

根据我的理解,gcc的某个版本对stdarg.h的处理方式发生了变化,这导致了上面提到的问题。

0

另外,你可以 使用 ActivePython,这样就不需要自己去 编译东西了:

$ 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
$
6

最新版本的XCode不再支持编译旧的PowerPC(PPC)架构。可惜的是,Mac上的Python通常还是会尝试为PPC和x86这两种架构构建C扩展。为了避免这个问题,可以在像'setup.py install'或'easy_install'这样的命令前面加上ARCHFLAGS设置,只包含你想要构建的架构:

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

撰写回答