pip安装numpy时的问题 - RuntimeError:工具链损坏:无法链接简单的C程序
我正在尝试在一个虚拟环境中安装numpy(还有scipy和matplotlib)。
不过我总是遇到这些错误:
RuntimeError: Broken toolchain: cannot link a simple C program
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1
我已经安装了Xcode的命令行工具。
$ which gcc
/usr/bin/gcc
$ which cc
/usr/bin/cc
我使用的是Mac OSX 10.9,Python是通过brew安装的。
编辑
是的,我是用pip来安装的。
整个错误信息非常长(超过400行)。
这里是其中的一部分:
C compiler: 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
compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c'
cc: _configtest.c
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
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
failure.
removing: _configtest.c _configtest.o
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/setup.py", line 192, in <module>
setup_package()
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/setup.py", line 185, in setup_package
configuration=configuration )
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/core.py", line 169, in setup
return old_setup(**new_attr)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/egg_info.py", line 10, in run
self.run_command("build_src")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 153, in run
self.build_sources()
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 164, in build_sources
self.build_library_sources(*libname_info)
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 299, in build_library_sources
sources = self.generate_sources(sources, (lib_name, build_info))
File "/Users/bdhammel/Documents/research_programming/julia_env/build/numpy/numpy/distutils/command/build_src.py", line 386, in generate_sources
source = func(extension, build_dir)
File "numpy/core/setup.py", line 674, in get_mathlib_info
raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program
13 个回答
如果你在使用Linux系统,可能需要安装一个C语言编译器,特别是当你看到类似 sh: gcc: command not found
的错误信息时。这说明你的系统里没有找到编译器。你可以按照下面的步骤来安装,我在这里简单总结了一下:
如果你使用的是Fedora、Red Hat、CentOS或Scientific Linux
# yum groupinstall 'Development Tools'
如果你使用的是Debian或Ubuntu Linux
$ sudo apt-get update $ sudo apt-get install build-essential manpages-dev
然后你可以尝试重新运行:
sudo pip install numpy
如果你不想使用sudo(这样在使用虚拟环境时权限等设置会被保留),你可以在你的.bash_profile文件中添加ARCHFLAGS的声明,然后正常运行。这在我使用Mavericks和Xcode 5.1的虚拟环境时是有效的:
在~/.bash_profile文件中:
export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future
然后,只需运行这个命令:
pip install --upgrade numpy
问题是你无法编译代码。
首先,确保你已经接受了Xcode的新条款和条件。你只需要打开Xcode,然后接受这些条款就可以了。
接下来,试着用下面的命令安装gcc:
brew install gcc
最后,试着用下面的命令安装Numpy:
pip install numpy
希望这些能帮到你。
对于Docker(Alpine)和Python 3.x,这个方法对我有效:
RUN apk update
RUN apk add make automake gcc g++ subversion python3-dev
虽然这个方法看起来不太好,但似乎能用。
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install --upgrade numpy
注意,如果你遇到的错误是关于其他包的,比如lxml,那在命令的最后要把numpy
换成那个包的名字。
我看到有人在安装一个gem时也遇到了类似的问题。
在Mavericks和Xcode 5.1上安装Ruby Gem Json失败 - 未知参数:'-multiply_definedsuppress'
这只是一个临时的解决办法,最终还是得修复编译器的选项。