1、pycharm 测试代码:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
x = torch.randn(1)
if torch.cuda.is_available():
device = torch.device("cuda")
y = torch.ones_like(x, device=device)
x = x.to(device)
z = x + y
print(z)
print(z.to("cpu", torch.double))
run,提示:
Module Not Found Error: No module named 'torch'
2、解决办法
进入pytorch官网: https://pytorch.org/get-started/locally/
由于我的电脑没有GPU,故CUDA选择None ,此后 复制上图最终 Command 到 Anaconda Prompt .
run “1”种测试代码, 顺利执行。