(没下载过pytorch直接从第四步开始)
首先查看CUDA版本
cmd中输入 NVIDIA-smi
pip -V
我的版本是CUDA11.6,python3.9
import torch没有问题但是torch.cuda.is_available()此时返回的false,故进行以下操作:
1.在base环境中输入 pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
此时报错:
原因是可能在当前环境中之前安装过 PyTorch,并import torch选择了 CUDA运行时附带的“默认”安装。
需要卸载所有 PyTorch直到找不到任何安装。
2.输入conda list 发现此时列表中有pytorch
3.在base环境中使用pip卸载Pytorch
pip uninstall torch torchvision -y
4.再重新运行
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
不过这个文件有2GB多,下载速度太慢,如果网速不好很可能下载失败。
5.在浏览器中输入网址
https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp39-cp39-win_amd64.whl
https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp39-cp39-win_amd64.whl
直接把文件下载下来,
6.再在base环境中输入pip install 并将文件直接拖进来
同理对另一个文件也进行如上操作
举个栗子,我存放的位置是D:\torchvision-0.14.1+cu117-cp39-cp39-win_amd64.whl
就输入 pip install D:\torchvision-0.14.1+cu117-cp39-cp39-win_amd64.whl
7.最后检验安装是否成功