安装 numpy 时出现 "Could not build wheels for numpy which use PEP 517 and cannot be installed directly" 错误

Getting an error saying "Could not build wheels for numpy which use PEP 517 and cannot be installed directly" while installing numpy

我正在尝试在 python 虚拟环境中使用命令 pip install numpy=1.19.1 安装特定版本的 numpy。但是我收到以下错误

ERROR: Failed building wheel for numpy
Failed to build numpy
ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly

我该如何解决这个问题?我正在使用 Python 3.9.6 和 Pip 21.1.3。我在 macOS Big Sur 上。

我认为 NumPy 尚未为 Python 3.9 做好准备,因为他们需要检查很多次。你应该尝试 Python 3.7 或 3.8 更好。

查看此主题:https://github.com/numpy/numpy/issues/17569

编辑: 根据 numpy 网站上的 latest news(日期为 12 月 31 日),Numpy 现在似乎也支持 python 3.9 和 3.10

如果您使用 Windows,请安装 Visual Studio 2019 Build Tools,然后转到 'Individual components',然后勾选 'Windows 10 SDK' 的最新版本,然后 'MSVC v142 x64/86 build tools - Latest'。这为我解决了这个错误,除了我这个错误是在安装 discord.py.

时出现的

首先尝试看看它是否适用于 Python 3.8,就像 Dhananjay 的回答一样。这可以为您节省大量存储空间,因为 Visual Studio 占用了大量 space。如果还是不行,你可以试试我的回答。

编辑:我刚刚意识到,你说你在 Mac。试试这个:

  • 在终端中输入 python -VV
  • 应该这样写:
Python 3.9.6 (default, Jun 29 2021, 10:19:25)
[GCC 10.3.0]

第二行的内容就是您需要安装的内容。我在 WSL2 的 Ubuntu 21.10 上使用 Python,它使用 GCC 10.3.0,并且我安装了 GCC 10.3.0。

是的,我也在使用 python 3.10 并切换回 python 3.8。

选中此 link python/downloads 下载 python 3.8

与上面的答案类似,切换到 Python 3.8 解决了这个问题。此外,由于这个问题,我无法安装依赖于 numpy 的 scikit-image

我使用 conda 创建了一个 Python 3.8 的虚拟环境,即 conda create -n py38 python=3.8 切换 python 版本。我已将 Mac M1,2020 更新到 OS Monterey,版本 12.0.1。

我在 MacBook Air(macOS BigSur) 笔记本电脑上通过 VS Code 的集成终端安装 Numpy 包时遇到了同样的错误。我找到了解决方案: 所以之前我使用的是旧版本的 pip,即 19.2.3。 但是当我使用命令

将它升级到最新版本时
pip install --upgrade pip

然后 运行 命令

pip install numpy 

它工作得非常好。

当时运行上面的命令,我的python版本是3.8.2。