安装Python库时出现“'cc' failed with exit status 1”错误

37

像许多其他人一样,我在安装Python库时遇到了问题(已下载为tar文件,然后进行了解压)。

rodolphe-mbp:python-Levenshtein-0.11.2 Rodolphe$ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to python_Levenshtein.egg-info/requires.txt
writing python_Levenshtein.egg-info/PKG-INFO
writing namespace_packages to python_Levenshtein.egg-info/namespace_packages.txt
writing top-level names to python_Levenshtein.egg-info/top_level.txt
writing dependency_links to python_Levenshtein.egg-info/dependency_links.txt
writing entry points to python_Levenshtein.egg-info/entry_points.txt
reading manifest file 'python_Levenshtein.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*' under directory 'docs'
warning: no previously-included files matching '*pyc' found anywhere in distribution
warning: no previously-included files matching '.project' found anywhere in distribution
warning: no previously-included files matching '.pydevproject' found anywhere in distribution
writing manifest file 'python_Levenshtein.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-intel/egg
running install_lib
running build_ext
building 'Levenshtein' extension
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c Levenshtein.c -o build/temp.macosx-10.9-intel-2.7/Levenshtein.o
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1

如其他地方提到的,我尝试在终端中输入“ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future sudo python setup.py install”,但没有成功。

有没有解决这个问题的办法,这个问题似乎是在 xcode 5.1 中出现的?

3个回答

76

在构建之前,请在您的终端中运行以下两行命令:

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

这些导出告诉编译器忽略未使用的参数而不是抱怨它们。


原因似乎是Python使用构建选项编译模块,除了其中一个选项在Mavericks上不再起作用:

 

苹果默认使用的clang 3.4会对未知标志报错,但CPython使用最初编译时相同的标志集构建模块。

(来自:https://dev59.com/MOo6XIcBkEYKwwoYKQ_G#22315129)

许多人都遇到了这个问题:


非常感谢!我之前尝试过,但没有成功。然而,在安装程序中直接使用“-E”标志解决了问题。 - Lucien S.
7
如果你正在使用 sudo 命令,那么是的,你需要使用 sudo -E 命令来传递环境变量。如果只是在一个你有写入权限的目录中进行构建,则这并不重要。 - Seth
1
这些标志太棒了! - andilabs
1
嘿,这个标志没帮到我;/ 我尝试安装“sudo pip install pywfdb” 但是我得到了这些错误;/ - Shial

35

我的问题在于我刚刚升级了XCode,需要安装命令行工具(请参见此答案)。

运行xcode-select --install后,我的python库成功安装了。


2
是的,这解决了我的Python安装问题。 - Nagendra Rao
2
对我有用;非常感谢! - Aravind

8

在(您下载的程序文件夹内部)安装

sudo -E python setup.py install

做得好!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接