PyTorch 选择版本
打开Pytorch官网,
htps://pytorch.org/get-started/locally/Start Locallyhttp://htps://pytorch.org/get-started/locally/
根据需要选择要安装的PyTorch版本

在本例子中,这里选择最新的版本12.1生成的安装命令
bash
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
注意,生成的安装指令默认是使用pip3,如果你用pip的改一下即可。
PyTorch 安装
PyTorch安装,开始执行安装,如下图:

提示安装完成,如下图:

验证PyTorch安装
验证PyTorch安装,执行下面python代码:
python
import torch
if __name__ == '__main__':
# 检测cuda环境
print(torch.cuda.is_available())
验证结果为True,安装成功。
