1. 程式人生 > >【Python】用pip安裝python庫下載超時的解決辦法

【Python】用pip安裝python庫下載超時的解決辦法

超時提示

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  ########################################
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.

解決辦法

源地址不穩定,下載速率慢,可以通過修改源地址解決。

方法一

直接在命令列中指定源地址,如下:
pip install -i https://pypi.doubanio.com/simple/ 包名
或者:
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple 包名
以上兩個源地址的下載速度都很快。

方法二

在配置檔案中修改源地址,如下: 建一個 ~/.pip/pip.conf檔案,新增內容如下
[global]
index-url = http://b.pypi.python.org/simple
[install]
use-mirrors = true
mirrors = http://b.pypi.python.org
也可以在[global]中加入timeout = 6000,以防止網速過慢情況下包下載不完