我是直接把对应的包直接下载下来,然后手工配环境!这样可以避免很多报错!!!
torch-GPU的下载地址:
https://download.pytorch.org/whl/torch_stable.html
https://download.pytorch.org/whl/torch/
这两个都可以!
使用方法:
①下载对的torch版本!!!
②下载对的CUDA版本!!!
③下载对的Python版本!!!
④下载对的操作系统!!!
这四个一个都不能错!!!一定要看仔细!!!
1.打开ana prompt
2.cd 到whl文件所在的文件夹路径之中
3.pip install + 对应的whl文件名 一定要加whl
一定要关翻墙!!!——不管翻墙装不上去!
也可以直接
pip install D:\torchgpuwhl\torch-1.5.1-cp37-cp37m-win_amd64.whl
一定要已经在自己的电脑里的(文件会比较大,推荐放到D盘里)

我还踩过这些坑!↓
cp表示的是对应环境的Python版本号,一旦没有对上会pip不上去
报错:ERROR: torch-1.5.1+cu101-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
如果遇到了报错:
Collecting package metadata (current_repodata.json): failed。
An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get
You will need to adjust your conda configuration to proceed.
Use conda config --show channels to view your configuration’s current state,and use conda config --show-sources to view config file locations.
PackagesNotFoundError: The following packages are not available from current channels:
解决方案:
正确的解决方法:
先删除已经设定好滴默认镜像源,执行下面的命令后就恢复了原来的源
conda config --remove-key channels
重新添加清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
重新执行这条命令:
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch