简体   繁体   English

在 Windows 10 for python 3.7 上使用 pip 安装 numpy

[英]Installing numpy with pip on windows 10 for python 3.7

I installed python 3.7 on my Windows 10 laptop since it has been officially released as of today (06/28/2018).自从今天(2018 年 6 月 28 日)正式发布以来,我在我的 Windows 10 笔记本电脑上安装了 python 3.7。 Then i tried to install numpy package using pip然后我尝试使用 pip 安装 numpy 包

pip install numpy

The install proceeds but finally fails with the below error :安装继续进行,但最终失败并出现以下错误:

        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 ""c:\program files\python37\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\pcheg\\AppData\\Local\\Temp\\pip-install-7wjkw5wn\\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 C:\Users\pcheg\AppData\Local\Temp\pip-record-uhj8233f\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\pcheg\AppData\Local\Temp\pip-install-7wjkw5wn\numpy\

Any ideas as to how to overcome this install Error?关于如何克服此安装错误的任何想法? Thanks.谢谢。

Installing NumPy on Windows is a common problem if you don't have the right build setup.如果您没有正确的构建设置,在 Windows 上安装 NumPy 是一个常见问题。 Instead, I always go to Christoph Gohlke's website to download the wheels you can install for your computer.相反,我总是去Christoph Gohlke 的网站下载可以为您的计算机安装的轮子。 Christoph generously builds the libraries himself with the right build environment and he posts it on his website. Christoph 慷慨地使用合适的构建环境亲自构建了库,并将其发布在他的网站上。


Newer Instructions - For older instructions, please scroll down较新的说明 - 有关较旧的说明,请向下滚动

First, install pipwin from PyPI which will install a utility that acts like pip but it will download the actual package you're interested in from his website, then use pipwin install to install the package you want.首先,从 PyPI 安装pipwin ,它将安装一个类似于pip的实用程序,但它会从他的网站下载您感兴趣的实际包,然后使用pipwin install安装您想要的包。

First do:首先做:

pip install pipwin

When that's installed, you can then do:安装后,您可以执行以下操作:

pipwin install numpy

This will install the latest version of NumPy on your system.这将在您的系统上安装最新版本的 NumPy。 This way you don't have to specifically search for the version of NumPy that is for your specific version of Python.这样您就不必专门搜索适用于您的特定 Python 版本的 NumPy 版本。


Older instructions较旧的说明

Go to the NumPy section: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy then download the version for 3.7 that is compatible with your version of Python (2 or 3 and 32-bit or 64-bit).转到 NumPy 部分: https : //www.lfd.uci.edu/~gohlke/pythonlibs/#numpy然后下载与您的 Python 版本(2 或 3 和 32 位或 64-少量)。 For example, the filename numpy‑1.14.5+mkl‑cp37‑cp37m‑win_amd64.whl is for NumPy 1.14.5, Python 3.7 - 64 bit.例如,文件名numpy‑1.14.5+mkl‑cp37‑cp37m‑win_amd64.whl适用于 NumPy 1.14.5,Python 3.7 - 64 位。 You can pick out which version of NumPy and which version of the Python interpreter and bit version you need in the filename.您可以在文件名中选择您需要哪个版本的 NumPy 以及哪个版本的 Python 解释器和位版本。

Doing this never requires you to build NumPy yourself or install the required compiler as opposed to installing NumPy through PyPI.与通过 PyPI 安装 NumPy 相比,这样做永远不需要您自己构建 NumPy 或安装所需的编译器。 You can just download the wheel and install it yourself.您只需下载轮子并自行安装即可。 Assuming you've already downloaded it, just do:假设您已经下载了它,只需执行以下操作:

pip install numpy‑1.14.5+mkl‑cp37‑cp37m‑win_amd64.whl

... assuming the wheel is in the directory you're currently in. ...假设轮子在您当前所在的目录中。

For windows when you install a package you type in Python 3:对于 Windows,当你安装一个你输入 Python 3 的包时:

py -m pip install [packagename]

         OR

py -m pip install numpy

You're probably missing a C compiler.您可能缺少 C 编译器。 If numpy doesn't provide a prebuilt wheel yet, you'll need to install a compiler.如果 numpy 还没有提供预构建的轮子,你需要安装一个编译器。 This website shows the one you need to install. 网站显示了您需要安装的网站。 For 3.7, I assume it's still 14.0, so you should install Microsoft Build Tools for Visual Studio 2017 .对于 3.7,我假设它仍然是 14.0,所以你应该安装Microsoft Build Tools for Visual Studio 2017

Let me know if that works.让我知道这是否有效。

Starting 24 November 2021, latest numpy require at least Python 3.8从 2021 年 11 月 24 日开始,最新的 numpy 至少需要 Python 3.8

Note: This might not be the original question asked, but it might help anyone come here.注意:这可能不是最初提出的问题,但它可能会帮助任何人来到这里。

To use python 3.7, latest numpy you can use is v1.21.4.要使用 python 3.7,您可以使用的最新 numpy 是 v1.21.4。 So, to install it, use:因此,要安装它,请使用:

pip install numpy==1.21.4

If you write requirements that you hope compatible with python 3.7, you can use numpy<=1.21.4如果您编写的要求希望与 python 3.7 兼容,则可以使用numpy<=1.21.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM