问题描述

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

使用了这个命令之后

import torch  
  
print(torch.cuda.is_available())#输出为false

输出仍然为false

解决办法

使用这两个命令将

pip uninstall torch torchvision torchaudio filelock typing-extensions sympy networkx jinja2 fsspec mkl numpy pillow
pip cache purge

下载相关的包彻底删除,第一个命令是移除包,第二个命令是清除缓存

重新使用,注意这里一定不能使用清华的源,不然仍然会是false

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

命令下载,如果第一个下载的包大小为2.4g就可以print(torch.cuda.is_available())输出就为true了
但是如果第一个下载的包大小为150mb左右,输出就仍然会是false,原因是使用了清华的源,会下载轻量版的torch
所以不要再后面加上清华源进行下载

错误命令

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple

在这里插入图片描述

正确命令

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

在这里插入图片描述

总结

根本原因是使用了清华源的轻量版torch导致的问题。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐