【已解决】torch.cuda.is_available()返回 False
这里笔者的理解是虚拟环境中的torch和本机中的torch是隔离的,所以需要检查替换虚拟环境中的torch版本。此时版本正确且 torch.cuda.is_available()返回True。此时可以看到虚拟环境中的torch版本就错了,先卸载。但是在虚拟环境py38中进行测试时仍旧报错。笔者这里首先在终端中安装了torch。如何找到正确版本我这里就不再赘述。跑一下代码也是ok的。
·
大致流程
省流版:
终端中配置好的torch不能在虚拟环境中直接使用,需要进入虚拟环境中检查配置。
在终端中安装好对应版本的torch后在conda虚拟环境中仍返回False
笔者这里首先在终端中安装了torch
但是在虚拟环境py38中进行测试时仍旧报错
这里笔者的理解是虚拟环境中的torch和本机中的torch是隔离的,所以需要检查替换虚拟环境中的torch版本。
首先检测torch版本,因为直接进行pip安装的torch可能是cpu版本
import torch
print(torch.__version__)
此时可以看到虚拟环境中的torch版本就错了,先卸载
pip uninstall torch
重新在虚拟环境中安装对应版本的torch
如何找到正确版本我这里就不再赘述。
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
再次进行测试
此时版本正确且 torch.cuda.is_available()返回True。
跑一下代码也是ok的。
更多推荐
已为社区贡献1条内容
所有评论(0)