[Solved] Resolve pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool

Solve pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=’files.pythonhosted.org’, port=443): Read timed out problem

Install torch with the command:

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

At this time, the error is reported:

pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='download.pytorch.org', port=443): Read timed out.

2. Analyze the cause of the problem

(1) There is a high probability that it is a network problem, that is, the network speed provided by Alibaba Cloud’s mirror source is not enough to support 2G torch installation
(2) Maybe the version does not match, but the command I copied on the official website for this problem: the command provided by the torch installation official website should not be a big problem.

3. Solutions

Switch mirror source:
Douban: http://pypi.douban.com/simple/
Tsinghua University: https://pypi.tuna.tsinghua.edu.cn/simple
Aliyun: http://mirrors.aliyun.com/pypi/simple/
Shandong University of Technology: http://pypi.sdutlinux.org/
University of Science and Technology of China https://pypi.mirrors.ustc.edu.cn/simple/
Huazhong University of Science and Technology: http://pypi.hustunique.com/
So the command can be changed to:

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

Or try a mirror image one by one, and it will always work!

4. The method provided by Daniel

If your internet speed has been slowing down and the above methods still can’t solve it, then you can use the following solutions:

pip --default-timeout=1688 install library name -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

Then you can use this method to install torch and torchvision respectively here
That is, use the command:

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

The --default-timeout=1688 here actually means to make the detection delay longer to prevent direct errors due to your network problems