conda使用国内源安装pytorch

1、添加国内源 用记事本打开C:\Users\LZL\.condarc,添加以下内容: channels:- https://mirrors.tuna.ts

1、添加国内源

用记事本打开C:\Users\LZL\.condarc,添加以下内容:

channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
ssl_verify: true
show_channel_urls: true

注:没有此文件就创建一个.condarc,路径中的LZL需要改成你的用户名。

2、查看本机CUDA版本

命令行输入:nvidia-smi。如下图所示,我的CUDA版本是11.2。

3、conda安装pytorch

pytorch官网查看安装命令,用国内源一定要去掉后面的-c pytorch,因为这是指定用官方源安装的命令。

Linux直接在命令行,Windows在Anaconda Prompt命令行输入:

conda install pytorch torchvision torchaudio cudatoolkit=11.3

注:cudatoolkit版本,需要匹配本机CUDA版本(11.3)。
pytorch-cpu表示指定cpu版,不指定默认为gpu版(若国内源无对应cuda版本的,则自动安装cpu版)

4、安装完毕,查看pytorch版本