#解决python3.7与torch版本不匹配问题
##问题:RuntimeError: The NVIDIA driver on your system is too old (found version 10010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver.
##解决:
pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
安装cuda101 torch==1.8.0版本
pip install torch==1.8.0+cu101 torchvision==0.9.0+cu101 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
问题:RuntimeError: No CUDA GPUs are available
解决方法:
// 检测一下cuda是否可用
print(torch.cuda.is_available())
False
//重新在文件头加入下面说明
import torch
torch.cuda.current_device()
torch.cuda._initialized = True
解决方法:
1、首先在报错的位置net.cuda前加入cuda检测语句:
print(torch.cuda.is_available())
1
输出为False,证明cuda不可用
2、检查本机中的cuda是否安装成功,且版本号是否与pytorch的版本号对应。检查发现没有问题
3、检查os.environ[“CUDA_VISIBLE_DEVICES”] = "1"语句,将1改为0,再运行无误。原因可能是本机上只有一个cuda,序号应为0。
参考博客
解决方案2:
- 在这个网站找到与cuda相关的torch版本,并下载:
https://download.pytorch.org/whl/cu101/torch_stable.html - 下载后使用:pip install 刚刚下载的文件名。进行安装
- 验证是否安装成功:
python
import torch
print(torch.__version__)
#输出版本
print(torch.cuda.is_available())
#输出:true
完成以上步骤安装成功!