pytorch官网
1.安装环境创建
这里介绍使用anaconda的环境创建过程。打开anaconda,选择environment,点击create,输入环境名称,对应python版本,点击create。
修改镜像源
在C盘用户目录下有个.condarc的文件,只要修改里面的参数即可,下面提供以下本人修改后的,这里换成了清华源,别的镜像源也一样修改即可。
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- 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
ssl_verify: true
remote_read_timeout_secs: 600.0
除了直接暴力修改.condarc文件外,你也可以使用终端命令进行修改:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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/msys2/
对于pytorch,需要加入新的源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
注意一会儿安装pytorch库的时候,记得去掉结尾的 -c pytorch 不然会影响安装的速度。
设置时间参数:
conda config --set remote_read_timeout_secs 600.0
2.conda命令安装
进入pytorch官网,选择下述专栏,查找对应的下载命令。
比如,cuda10.1对应的pytorch版本的下载命令:conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.1 -c pytorch
直接在创建好的环境终端中输入所调用下载命令。
3.本地安装
有时候上面的安装会遇到报错:
受网速影响,即使是进行换源,设置时间,也会一直会安装失败,这时候就需要我们使用本地安装的方法。
进入pytorch下载网址:link.选择对应的安装版本进行本地下载。
本人下载的是pytorch1.5.0对应着python3.6的版本,如下图:
等待下载完成。
(进入之前建好的环境中,这里我配置另外一个环境)打开终端进入下载文件所在文件夹,接着输入命令pip install torch-1.5.0+cu101-cp36-cp36m-win_amd64.whl
,等待安装完成即可。