一. CPU版本安装
在官网选择对应版本进行安装
pip install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html -i https://mirrors.aliyun.com/pypi/simple/
验证是否安装成功
import torch
x = torch.rand(5, 3)
print(x)
二. GPU版本安装
如果是nvidia显卡可在此处下载CUDA工具包并选择适合自己电脑的版本自行安装
选择pytorch版本
在官网选择对应自己cuda版本的pytorch进行安装
# 示例
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html -i https://mirrors.aliyun.com/pypi/simple/
验证
输出True说明安装成功
import torch
print(torch.cuda.is_available())
三. 可视化工具
pip install matplotlib -i https://mirrors.aliyun.com/pypi/simple/