安装步骤
1.创建虚拟环境
conda create -n pt1.10.1 python=3.8
2.激活虚拟环境
conda activate pt1.10.1
3.安装gpu版pytorch
# pytorch1.10.1
pip install torch==1.10.1+cu111 torchvision==0.9.0+cu111 torchaudio===0.8.0 -f https://download.pytorch.org/whl/cu111/torch_stable.html
pip install torch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 #(装的是cpu版本)
# pytorch2.0
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117(同时安装cudnn,cuda11.7,装的是2.0版本的torch)
测试安装是否成功
import torch
print(torch.__version__)
print(torch.cuda.is_available())
上面如果总是安装失败,可以试试下面这个方法
https://blog.csdn.net/weixin_39450145/article/details/125669330
# CUDA 11.3, pytorch1.11.0
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113