在开始程序中打开Anaconda Prompt一行一行输入
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
conda config --set show_channel_urls yes
conda create -n pytorch python=3.8
(注释:通过conda create -n pytorch python=3.9命令创建pytorch环境,python的版本可以自由选择)
y
conda activate pytorch
conda install pytorch torchvision torchaudio cudatoolkit=10.2
y
测试一下
import torch
torch.cuda.is_available()