(没下载过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:/

当CUDA版本为11.6且torch.cuda.is_available()返回False时,文章提供了详细步骤来解决这一问题。首先,确认环境中无冲突的PyTorch版本,然后卸载所有PyTorch,再通过指定CUDA版本的whl文件进行重新安装,以确保与CUDA版本匹配。最后,验证安装是否成功。
最低0.47元/天 解锁文章
1110

被折叠的 条评论
为什么被折叠?



