pip install 安装超时失败怎么解决?

作者: xusx 分类: Python 发布时间: 2023-02-12 10:54 浏览:568
python

问题

例如,执行下面语句:

python -m pip install --upgrade pip

几分钟后报错:

pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
WARNING: You are using pip version 19.2.3, however version 23.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

应该是请求超时造成的安装失败。

解决

作为一名程序员,代理是必不可缺的。设定一个代理,加到安装命令后面:

python -m pip install --upgrade pip --proxy=127.0.0.1:1080

执行安装成功:

Collecting pip
  Downloading https://files.pythonhosted.org/packages/ab/43/508c403c38eeaa5fc86516eb13bb470ce77601b6d2bbcdb16e26328d0a15/pip-23.0-py3-none-any.whl (2.1MB)
     |████████████████████████████████| 2.1MB 48kB/s
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
Successfully installed pip-23.0

其他亦如是:

pip install redis --proxy=127.0.0.1:1080

当然,还有种解决方式是,修改  pip 源 ,简单的如:

pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install tensorflow-hub -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

国内有几个名气比较大的源:
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!