Python pip install numpy 的问题 - RuntimeError: Broken toolchain: cannot link a simple C program

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22388519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:50:07  来源:igfitidea点击:

Problems with pip install numpy - RuntimeError: Broken toolchain: cannot link a simple C program

pythonnumpyvirtualenvpip

提问by Ben

I'm trying to install numpy (and scipy and matplotlib) into a virturalenv.

我正在尝试将 numpy(以及 scipy 和 matplotlib)安装到 virturalenv 中。

I keep getting these errors though:

我不断收到这些错误:

RuntimeError: Broken toolchain: cannot link a simple C program

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1

I have the command line tools for xcode installed

我已经安装了 xcode 的命令行工具

$ which gcc
/usr/bin/gcc
$ which cc
/usr/bin/cc

I'm on Mac OSX 10.9 Using a brew installed python

我在 Mac OSX 10.9 上使用 brew 安装的 python

Edit
Yes, trying to install with pip.
The whole traceback is huge (>400 lines)

编辑
是的,尝试使用 pip 安装。
整个追溯是巨大的(> 400 行)

Here is a section of it:

这是它的一部分:

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

采纳答案by Derrick Shoemake

While it's ugly, it appears to work

虽然它很丑,但它似乎有效

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install --upgrade numpy

Note that if you are getting this error for a package other than numpy, (such as lxml) specify that package name instead of numpyat the end of the commnd.

请注意,如果您为 numpy 以外的包(例如 lxml)收到此错误,请指定该包名称而不是numpy在命令的末尾。

I saw a similar issue someone was having with installing a gem

我看到有人在安装 gem 时遇到了类似的问题

Ruby Gem install Json fails on Mavericks and Xcode 5.1 - unknown argument: '-multiply_definedsuppress'

Ruby Gem 在 Mavericks 和 Xcode 5.1 上安装 Json 失败 - 未知参数:'-multiply_definedsuppress'

This is only a temporary fix, at some point the compiler options will have to be fixed

这只是一个临时修复,在某些时候必须修复编译器选项

回答by Brian

If you don't want to use sudo (so permissions and things like that are preserved when using venv), you can add the ARCHFLAGS declaration to your .bash_profile, and run as normal. This worked for me with Mavericks and Xcode 5.1 using with venv:

如果您不想使用 sudo(因此在使用 venv 时会保留权限和类似内容),您可以将 ARCHFLAGS 声明添加到您的 .bash_profile 中,然后正常运行。这对小牛队和 Xcode 5.1 与 venv 一起使用对我有用:

In ~/.bash_profile:

在 ~/.bash_profile 中:

export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future

export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future

Then, just run the command:

然后,只需运行以下命令:

pip install --upgrade numpy

pip install --upgrade numpy

回答by Iliyan Bobev

The above worked for me only after installing python3-dev.

以上仅在安装 python3-dev 后才对我有用。

回答by Desmond

The problem is that you are unable to compile.

问题是你无法编译。

First, make sure that you have accepted the new Terms and Conditions with Xcode. To do this, just open up xCode and accept.

首先,确保您已接受 Xcode 的新条款和条件。为此,只需打开 xCode 并接受即可。

Then, try installing gcc with

然后,尝试安装 gcc

brew install gcc

Finally, try to install Numpy with

最后,尝试安装 Numpy

pip install numpy

Hope this helps.

希望这可以帮助。

回答by user3589327

I simply had to open XCode and accept the agreement and let it install the tools. I then went back to PyCharm and installed numpy again with no issues.

我只需要打开 XCode 并接受协议并让它安装工具。然后我回到 PyCharm 并再次安装 numpy,没有任何问题。

回答by lukecampbell

In some cases after OS X upgrades XCode, XCode will require the user (with administrative privileges) to accept a new license. Until the license is accepted, clang and gcc will issue an error when attempting to compile and link code. Or at least python packages.

在某些情况下,OS X 升级 XCode 后,XCode 将要求用户(具有管理权限)接受新的许可证。在许可证被接受之前,clang 和 gcc 在尝试编译和链接代码时会发出错误。或者至少是 python 包。

If you launch XCode and accept the license, the errors no longer appear.

如果您启动 XCode 并接受许可,错误将不再出现。

At least, this was the case for me.

至少,对我来说是这样。

回答by Inc33

This means it can't find your C compiler. Try installing the gcc compiler if linking other compiler fails.

这意味着它找不到您的 C 编译器。如果链接其他编译器失败,请尝试安装 gcc 编译器。

回答by Ollegn

For fedora users that are having a similar problem try installing these packeges:

对于遇到类似问题的 Fedora 用户,请尝试安装这些软件包:

(if not using python3 use python-devel and pip instead of pip3)

(如果不使用 python3,请使用 python-devel 和 pip 而不是 pip3)

sudo dnf install python3-devel
sudo dnf install make automake gcc gcc-c++ gcc-gfortran
sudo dnf install redhat-rpm-config
sudo dnf install subversion

then try

然后尝试

sudo pip3 install numpy

回答by avyk37

If you are running a linux distribution, you may need a C compiler, especially if you see telltale log lines like sh: gcc: command not found. You can follow the instructions here, which I've summarized below:

如果您运行的是 linux 发行版,您可能需要一个 C 编译器,尤其是当您看到像sh: gcc: command not found. 您可以按照此处的说明进行操作,我总结如下:

  • Fedora, Red Hat, CentOS, or Scientific Linux

    # yum groupinstall 'Development Tools'

  • Debian or Ubuntu Linux

    $ sudo apt-get update $ sudo apt-get install build-essential manpages-dev

  • 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

Then you can try rerunning:

然后你可以尝试重新运行:

sudo pip install numpy

回答by zenperttu

On Fedora 22 this was resolved by updating pip itself: sudo pip install --upgrade pip

在 Fedora 22 上,通过更新 pip 本身解决了这个问题: sudo pip install --upgrade pip