从Pytorch官网上可以看到有多种安装方式:
比较常见的方法是通过pip和conda安装,当使用conda安装的时候,可能会遇到下载过慢的问题,尤其是文件:pytorch-1.0.1- py3.7_cuda110_cudnn8_0.tar.bz2,下载的时候可能会遇到无尽的等待。这里推荐用清华源替代默认conda源的方法,可以解决下载过慢的问题。
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/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
据Python和CUDA选择对应的版本,然后官方给出提示可通过运行:
conda install pytorch torchvision cudatoolkit=11.0 -c pytorch
但是这里一定要注意,去掉-c pytorch,安装的时候才会默认从清华源下载相应的包,因此这里用命令行:
conda install pytorch torchvision cudatoolkit=11.0
然后安静等待,就可以安装成功了
安装成功后 python
import torch
import torchvision
不报错即可安装成功