解决torch.cuda.is_available()为false的方法+总结ubuntu中安装pytorch(gpu版本)的方法

太激动啦啦啦。。。先来看一波

zhenghan@zhenghan:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Tue_Jun_12_23:07:04_CDT_2018
Cuda compilation tools, release 9.2, V9.2.148
zhenghan@zhenghan:~$ python
Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available();
True
>>> 


终于知道为什么我的torch.cuda.is_available()总为false,原因是我的显卡驱动太低,与CUDA不匹配。装的pytorch是1.4+cuda9.2版本的
解决torch.cuda.is_available()为false的方法+总结ubuntu中安装pytorch(gpu版本)的方法_第1张图片
9.2的必须显卡驱动大于396,而自己的显卡驱动是390,那肯定不匹配咯。
因此,升级显卡驱动,
设置->软件更新->附加驱动->选择nvidia最新驱动(361)->应用更改,选择435这一行,应用更改,完了重启就好了。
解决torch.cuda.is_available()为false的方法+总结ubuntu中安装pytorch(gpu版本)的方法_第2张图片
最后,测试:

zhenghan@zhenghan:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Tue_Jun_12_23:07:04_CDT_2018
Cuda compilation tools, release 9.2, V9.2.148
zhenghan@zhenghan:~$ python
Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available();
True
>>> 

torch.cuda.is_available()为true 啦!

总结,写在最后,安装pytorch需要注意的地方:
1.看自己需要装的pytorch版本以及cuda要求,https://download.pytorch.org/whl/torch_stable.html 这个网站比较慢,但是能看到自己需要的版本要求,推荐用镜像网站去下:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/
2.查看自己的显卡驱动是否支持cuda,对应关系:
解决torch.cuda.is_available()为false的方法+总结ubuntu中安装pytorch(gpu版本)的方法_第3张图片
一定要注意驱动,cuda,pytorch是cpu版还是gpu版以及pytorch与cuda版本选择的关系。
具体的安装方法可参见我之前写的博客。

你可能感兴趣的:(环境安装)