安装Python库时出现“'cc'以状态1失败”的错误
和很多人一样,我在安装一个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 个回答
35
对我来说,问题是我刚刚升级了XCode,需要安装命令行工具(可以参考这个回答)。
在运行了 xcode-select --install
之后,我的Python库就顺利安装好了。
76
在你开始构建之前,先在你的命令行中运行这两行:
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
这些设置告诉编译器忽略那些没有用的参数,而不是对它们发出警告。
问题的原因似乎是,Python在编译模块时使用的是它最初构建时的选项,但其中有一个选项在Mavericks系统上不再有效:
苹果提供的clang 3.4默认会对未知的标志报错,而CPython在编译模块时使用的是它最初编译时的相同标志。
(来源: https://stackoverflow.com/a/22315129/65295)
很多人都遇到了这个问题:
8
在你下载的程序文件夹里进行安装
sudo -E python setup.py install
这样就搞定了!