前言

安装Pytorch,首先需要安装的是torch,做CV的常用的还有TorchVision,还有必不可少的cudatoolkit。

它们之间的版本有着严格的对应关系。

而官网提供的命令没有涵盖我们所需要的一些版本的对应(如下图所示),所以我们只能模仿官网的命令来下载。

在这里插入图片描述

在这里插入图片描述

我现在使用的是CUDA11.2,那么我要么使用cudatoolkit11.1和cudatoolkit11.2,而不能使用cudatoolkit11.3,因为不能向上兼容,只能向下兼容,升级CUDA很麻烦,我不想这么麻烦。

安装torch和torchvision

torch和torchvision对应关系

pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html

注:conda install 可能找不到源包,那就在虚拟环境中用 pip install.

安装cudatoolkit

配置清华镜像:

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/
anaconda show Zimmf/cudatoolkit

查找cudatoolkit:

anaconda search -t conda cudatoolkit

在这里插入图片描述
找到我需要的11.1版本的那一行:

anaconda show Zimmf/cudatoolkit

发现它里面有10.2和11.1的版本,选择我需要的11.1,安装:

conda install --channel https://conda.anaconda.org/Zimmf cudatoolkit=11.1

在这里插入图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐