建议先创建一个新虚拟环境,再安装pytorch。(跑不同的代码有些库的需求是不一样的,包括python的版本也不一样)
首先在cmd中创建虚拟环境conda create -n xxx python=3.x
比如conda create -n pytorch1 python=3.8
然后激活虚拟环境conda activate xxx
比如conda activate pytorch1
在该环境下安装pytorch
打开pytorch官网
不用单独下载cuda的版本,直接复制下面的代码pip3 install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
由于直接复制下载较慢建议加上清华源pip3 install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
直接复制即可使用