本人使用的显卡如下,打开任务管理器查看
Anaconda下载哪个版本都可以
使用命令conda create -n pytorch python=3.6创建一个名为pytorch的环境,解释器使用3.6的
使用命令conda activate pytorch进入该环境
进入pytorch官网,选择下列选项
复制上面的命令,在pytorch环境下载
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
进入python,导入 torch 包,检查 GPU 启动失败
(pytorch) C:\Users\ml>python
Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
False
在pytorch下使用 conda list 命令查看pytorch是 CPU 版本的
使用命令conda uninstall pytorch卸载 CPU 的版本
选择 pip 方式下载,会下载 GPU 版本
复制命令到pytorch环境下载
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117
没有找到匹配的版本,所以是11.7的版本太高,修改为 11.3版本,继续下载,这个过程很慢,需要耐心等待
最后检验,安装成功
或者直接运行这个命令
pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
或者
pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f 国内镜像源
或者
pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111