1 不要用powershell

在 PowerShell 里直接使用 conda activate 可能不起作用。 需要先运行 conda init powershell 并重启 PowerShell。但是我试了一下好像也没用,遂改用CMD。

PS C:\Users\eivver> conda activate d2l
PS C:\Users\eivver>

一检查python版本,发现根本没进d2l而是还在base…

2 注意python版本

如果出现类似错误:

PS C:\Users\eivver> pip install torch==1.12.0+cu116 torchvision==0.13.0+cu116 torchaudio==0.12.0+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com, https://download.pytorch.org/whl/cu116 
ERROR: Could not find a version that satisfies the requirement torch==1.12.0+cu116 (from versions: 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.4.0, 2.4.1, 2.5.0, 2.5.1, 2.6.0, 2.7.0, 2.7.1, 2.8.0) 
ERROR: No matching distribution found for torch==1.12.0+cu116

很大概率 不是源里没有,而是 你的 Python 版本不符合该 PyTorch 版本的 wheel 要求

原因分析:

  1. PyTorch 官方提供的 .whl 文件是针对特定 Python 版本和平台的。
    • 例如 torch-1.12.0+cu116-cp38-cp38-win_amd64.whl 就只支持 Python 3.8 Windows 64 位
  2. 当你用 pip 安装时,pip 会根据你当前的 Python 版本去匹配可用的 wheel 文件,如果没有匹配,就会报 “No matching distribution found”。
  3. 所以即使源里有对应版本,只要 Python 版本不匹配,也安装不了。

3 下载老版本PyTorch

可以到这个网址去找所需要的的平台和版本:https://pytorch.org/get-started/previous-versions/

可以通过 –extra-index-url 对应的网址查看该 CUDA 版本支持的 Python 版本

例如 : --extra-index-url https://download.pytorch.org/whl/cu116