MSYS2 pip install numpy 失败

Posted

技术标签:

【中文标题】MSYS2 pip install numpy 失败【英文标题】:MSYS2 pip install numpy failed 【发布时间】:2018-08-10 23:46:57 【问题描述】:

我是 MSYS2 的新手,所以我尝试使用 pip (mingw-w64-x86_64-python3-pip-9.0.1-3) 安装 numpy,但安装失败。这是输出:

(...) C编译器:x86_64-pc-msys-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -march=x86-64 -mtune=generic -O2 -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 -I/usr/include/python3.6m -c'
x86_64-pc-msys-gcc: _configtest.c
/usr/bin/bash: x86_64-pc-msys-gcc: command not found
/usr/bin/bash: x86_64-pc-msys-gcc: command not found
failure.
removing: _configtest.c _configtest.o
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-3d852664/numpy/setup.py", line 394, in <module>
    setup_package()
  File "/tmp/pip-build-3d852664/numpy/setup.py", line 386, in setup_package
    setup(**metadata)
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/core.py", line 169, in setup
    return old_setup(**new_attr)
  File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/command/install.py", line 62, in run
    r = self.setuptools_run()
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/command/install.py", line 36, in setuptools_run
    return distutils_install.run(self)
  File "/usr/lib/python3.6/distutils/command/install.py", line 551, in run
    self.run_command('build')
  File "/usr/lib/python3.6/distutils/cmd.py", line 314, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/command/build.py", line 47, in run
    old_build.run(self)
  File "/usr/lib/python3.6/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.6/distutils/cmd.py", line 314, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/command/build_src.py", line 148, in run
    self.build_sources()
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/command/build_src.py", line 159, in build_sources
    self.build_library_sources(*libname_info)
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/command/build_src.py", line 294, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
  File "/tmp/pip-build-3d852664/numpy/numpy/distutils/command/build_src.py", line 377, in generate_sources
    source = func(extension, build_dir)
  File "numpy/core/setup.py", line 675, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program

----------------------------------------

Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-3d852664/numpy/setup.py';f=getattr (tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec (compile(code, file, 'exec'))" install --record /tmp/pip-4nnf7xbj-record/install-record.txt --single-version-externally-managed --compile " 失败,错误代码 1 在 /tmp/pip-build-3d852664/numpy/

我已经安装了构建工具:我使用了https://github.com/orlp/dev-on-windows/wiki/Installing-GCC--&-MSYS2上的教程(我只有64位包)

我在网上寻找了类似的问题,但没有发现任何相关问题。 欢迎任何意见或建议

提前致谢

【问题讨论】:

【参考方案1】:
pacman -S mingw-w64-x86_64-python-scipy
pacman -S mingw-w64-i686-python-scipy

【讨论】:

您好,欢迎来到 SO。您能否添加引用标签并提供一些信息,这两种情况中的哪一种涵盖了哪些问题? 这并没有提供问题的答案。一旦你有足够的reputation,你就可以comment on any post;相反,provide answers that don't require clarification from the asker。 - From Review 安装正确的二进制包解决了“获取 numpy”的问题 - 不是严格意义上的“pip install failed”,但至少在我的情况下这是正确的解决方案。 请注意,这些不是 MSYS2 包,它们是 MINGW64 包 - 这意味着,它们只能在 MINGW64 外壳 (C:\msys64\mingw64\bin\python3.exe) 中使用 python 运行,而不是在 python 中运行MSYS2 shell(即C:\msys64\usr\bin\python3.exe【参考方案2】:

没有安装正确的 gcc 编译器。对于我的安装,我使用了 msys2 shell(不是 mingw)并安装了 msys/gcc 包:

pacman -S msys/gcc

【讨论】:

以上是关于MSYS2 pip install numpy 失败的主要内容,如果未能解决你的问题,请参考以下文章

pip install numpy 不起作用:“找不到匹配的发行版”

pip install "numpy" 在 android chaquopy 中导致错误

Python用pip install安装Scipy报错

python3安装pandas执行pip3 install pandas命令后卡住不动的问题及安装scipysklearn库的numpy.distutils.system_info.NotFound(

在Amazon EC2上安装numpy

python中 pip install --upgrade pip出错