task01——pytorch安装笔记

Pytorch在conda+CUDA10.2环境安装

前言

由于之前电脑里安装的CUDA是10.2版本的,paddlepaddle什么的也装的是CUDA10.2的版本,不想再去重装CUDA。

如图:官方已经不支持CUDA10.2的版本了。官网地址:PyTorch

task01——pytorch安装笔记

解决

安装过去的版本,点击上面的Previous PyTorch Versions,这里直接给个网址:Previous PyTorch Versions | PyTorch

可以看见有许多过去的版本,也有支持cuda10.2的,大家可以按需找自己要的
task01——pytorch安装笔记

完整过程

创建conda虚拟环境

conda create -n env_name python==3.7

激活环境

conda activate env_name

conda换源

方式一 命令行(比较方便)

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
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/pkgs/free/

建议把上面那些跑两遍

第一遍只能加channel,第二遍能把他们优先级提到默认源的前面(亲测被坑)

方式二 改文件

TUNA 提供了 Anaconda 仓库与第三方源的镜像,各系统都可以通过修改用户目录下的 .condarc 文件。Windows 用户无法直接创建名为 .condarc 的文件,可先执行conda config --set show_channel_urls yes生成该文件之后再修改。

完成这一步后,我们需要修改C:\Users\User_name\.condarc这个文件,打开后将文件里原始内容删除,将下面的内容复制进去并保存。

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

这一步完成后,我们需要打开Anaconda Prompt 运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。

安装pytorch

根据前面在官网找的支持cuda10.2的安装代码直接安装就好

#conda安装
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=10.2 -c pytorch
#pip安装
pip install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html

可以看到变成了清华源
task01——pytorch安装笔记

然而我自己试下来清华源下pytorch也是300k/s小水管,建议pip
可以看到变成了清华源

[外链图片转存中…(img-5JDl2Wns-1655178124349)]

然而我自己试下来清华源下pytorch也是300k/s小水管,建议pip

task01——pytorch安装笔记

成功!

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
社会演员多的头像社会演员多普通用户
上一篇 2022年6月15日
下一篇 2022年6月15日

相关推荐