安装pytorch 后torch.cuda.is_available()返回False的解决方法

今年安装pytorch 后一直只能安装上CPU版本,不能使用GPU。

参考了这篇博客的方法:完美解决torch.cuda.is_available()一直返回False的玄学方法(完美解决torch.cuda.is_available()一直返回False的玄学方法_python_脚本之家 (jb51.net)

因为我添加了清华源镜像,所以使用conda下载会直接选择清华源下载,后来上清华源的网站上看了下,可能是清华源没有对应cuda版本的pytorch,所以会装cpu版的。

上清华源网站查看安装的版本(我安装的是cuda 11.3,安装的pytroch版本为1.12.1)

 后面发现我在conda的虚拟环境安装的为python 3.8版本

重新删除环境后

conda remove -n pytorch --all

重新新建环境并安装python版本为3.10:

conda create -n pytorch python=3.10

安装完成后,在按照pytorch官网的安装

最后测试torch.cuda.is_available() 返回True,大功告成! 

扫描二维码关注公众号,回复: 17216152 查看本文章

猜你喜欢

转载自blog.csdn.net/zlbbme/article/details/126232042