解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects
作者:mmseoamin日期:2024-01-21

最近在学习李沐老师的深度学习的课程,在安装 d2l 时,

pip install d2l==0.17.6

遇到了问题:

ERROR: Could not build wheels for pandas, which is required to install pyproject.toml-based projects

由于我忘记截错误的图了,在论坛里找了别人的错误截图贴过来:

解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects,第1张

网上找了好多办法,有说 3.10 降到 3.9,有说 conda 删掉 d2l 重装的,有说网上下载 pandas 编译好的 wheel 直接替换的。尝试了都无法解决。

不过最后一个方法给了我灵感,既然 pip 是下载到本地后进行编译,那我应该可以下载编译好的产物或者源文件,直接安装?

我查了一下 python 官方文档是否支持本地安装,果然是支持的,所以通过本地安装这个包解决了问题:

  1. 在 https://pypi.org/project/d2l/1.0.0b0/#files ,推荐下载 wheel:

    d2l-1.0.0b0-py3-none-any.whl

    解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects,在这里插入图片描述,第2张

    官方文档也解释了更倾向于用 Wheel

    解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects,在这里插入图片描述,第3张

  2. 根据官方文档按以下命令,安装本地文件,路径换成你下载文件的本地路径,如:

python -m pip install "C:\Users\xxx\Downloads\d2l-1.0.0b0-py3-none-any.whl"

py 就是有些系统里 python 的别名,如果遇到输出找不到 py 对象就用 python

解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects,在这里插入图片描述,第4张

Installing Packages — Python Packaging User Guide

  1. 然后我们测试一下是否能正常 import d2l

    解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects,在这里插入图片描述,第5张

    不应该啊,都安装成功了,为啥还不行呢?

    突然想到什么,于是再输入一遍

pip install d2l==0.17.6

这次果然安装跑的很快,因为本地环境已经都有依赖的包了,再试一下,果然正常了:

解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects,在这里插入图片描述,第6张

解决 Could not build wheels for pandas, which is required to install pyproject.toml-based projects,在这里插入图片描述,第7张

猜测通过 python 本地安装的包,pip 并不能对应上包名称,无法找到路径,要再次通过 pip 安装,就能对应上了。