在安装pytorch时,官方提供的安装命令如下:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
在实际安装过程中,如使用官方提供的方法安装慢,可以采用从国内镜像下载离线安装的方法
1、进入阿里云的下载地址 https://mirrors.aliyun.com/pytorch-wheels
2、分别下载一下3个whl文件
torch-2.3.1+cu121-cp38-cp38-win_amd64.whl
torchvision-0.18.1+cu121-cp38-cp38-win_amd64.whl
torchaudio-2.3.1+cu121-cp38-cp38-win_amd64.whl
3、再用pip依次安装,如
pip install torch-2.3.1+cu121-cp38-cp38-win_amd64.whl
附:pytorch安装结果的检测方法
进入python环境,如命令torch.cuda.is_available()返回True,代表torch的GPU版本安装成功
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> torch.__version__ '2.3.1+cu121' >>> torch.version.cuda '12.1' >>> torch.cuda.is_available() True