使用命令安装torch:
pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
这时候报错:
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='download.pytorch.org', port=443): Read timed out.2.分析问题产生原因
(1)大概率是网络问题,也就是阿里云的镜像源提供的网速不足以支撑2个G的torch安装
(2)也许可能版本不匹配,但这一问题我在官方网站复制的命令:torch安装官网提供的命令,应该是问题不大的。
切换镜像源:
豆瓣:http://pypi.douban.com/simple/
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
山东理工大学:http://pypi.sdutlinux.org/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学:http://pypi.hustunique.com/
因此命令可以改为:
```powershell pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
或者一个一个镜像试过去,总会有效果的!
4.大牛提供的方法如果你的网速一直很拉闸,上面的方法依然解决不了,那这时可以使用如下的解决方案:
pip --default-timeout=1688 install 库名称 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
那在这里可以分别用该方法安装torch和torchvision
也就是使用命令:
pip3 --default-timeout=1688 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
这里的--default-timeout=1688其实意思就是让其检测延迟的时间变长,以防止因为你的网络问题而直接报错。以上有可能也会报错,因为你所选用的镜像源是不存在这样的包的,这时候可以切换镜像源。如下所示:
还没有使用这个技巧之前,前面好多次都是安装在了600多M就因为网络问题停止安装了,有一次甚至都2000多M了以为要成功的时候GG了,真的气哭了。
虽然安装成功了,但新的风暴又产生了:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. projectq 0.7.0 requires matplotlib>=2.2.3, which is not installed. projectq 0.7.0 requires networkx>=2, which is not installed. projectq 0.7.0 requires requests, which is not installed. projectq 0.7.0 requires scipy, which is not installed.
不过这个风暴,直接使用安装matplotlib包,其他几个包的命令也如下所示:
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
这样的代码块,将报错的几个包全部安装成功就了!
最后,在命令行下输入python:
(torchlearning) C:WINDOWSsystem32>python
然后进入python操作行输入一下代码:
import torch x = torch.rand(5, 3) print(x)
出现以上结果就表示torch终于TM的安装成功了!!!



