首先借鉴这篇文章
torch.cuda.is_available()返回false——解决办法_cuda available false-CSDN博客
如果你想在anaconda下的虚拟环境使用它,没问题,这里提供一个投机取巧的方法:
找到刚才在cmd中下载成功的三个东西,他们在你的anaconda目录下的lib->site-packages,例如我的在D:\anaconda\Lib\site-packages
,
这里的方法我不能正常使用,所以我在anaconda protempt中切换到指定的虚拟环境
使用pip方法重新安装
这里遇到了
查了查,说是默认的pip源的问题,这里可以使用国内的镜像
国内的一些pip源:
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
使用方法:在后面直接 -i 加 url
最后出现这样的错误
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.15.2+cu117 requires torch==2.0.1, but you have torch 2.0.0 which is incompatible.
发现是已经有2.0的torch,使用指令 pip uninstall torch,重新安装2.1版本的torch
python
import torch
torch.cuda.is_available()
最后验证成功,返回为True