python3 pip3 install 报错 ReadTimeoutError: HTTPSConnectionPool(host=‘xxx‘, port=443): Read timed 解决方法

目录

错误现象

方法一:手动指定源

方法二:更改默认源

方法三:手动设置延时


错误现象

Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    0% |                                | 4.1kB 17.7MB/s eta 0:00:01Exception:
Traceback (most recent call last):
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/basecommand.py",line 223,in main
    status = self.run(options,args)
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/commands/install.py",line 282,in run
    requirement_set.prepare_files(finder)
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/req/req_set.py",line 334,in prepare_files
    functools.partial(self._prepare_file,finder))
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/req/req_set.py",line 321,in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/req/req_set.py",line 491,in _prepare_file
    session=self.session)
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/download.py",line 825,in unpack_url
    session,File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/download.py",line 673,in unpack_http_url
    from_path,content_type = _download_http_url(link,session,temp_dir)
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/download.py",line 886,in _download_http_url
    _download_url(resp,link,content_file)
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/download.py",line 621,in _download_url
    for chunk in progress_indicator(resp_read(4096),4096):
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/utils/ui.py",line 133,in iter
    for x in it:
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/download.py",line 586,in resp_read
    decode_content=False):
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/_vendor/requests/packages/urllib3/response.py",line 307,in stream
    data = self.read(amt=amt,decode_content=decode_content)
  File "/Library/Python/3.7/site-packages/pip-7.1.0-py3.7.egg/pip/_vendor/requests/packages/urllib3/response.py",line 267,in read
    raise ReadTimeoutError(self._pool,None,'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org',port=443): Read timed out.

方法一:手动指定源

在 pip3 后面跟-i 来指定源,比如用豆瓣的源来安装 web.py 框架:

pip3 install numpy -i https://pypi.doubanio.com/simple/

注意后面要有 /simple/ 目录

国内可用源:

阿里云 :https://mirrors.aliyun.com/pypi/simple/

中国科技大学 :https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣(douban) :https://pypi.doubanio.com/simple/

清华大学: https://pypi.tuna.tsinghua.edu.cn/simple/

腾讯源:https://mirrors.cloud.tencent.com/pypi/simple

方法二:更改认源

需要创建或修改配置文件( linux 的文件在~/.pip/pip.conf , windows 在%HOMEPATH%\pip\pip.ini ),修改内容为:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

如果不加后面的 install

则需要每次在命令后面加上 --trusted-host

方法三:手动设置延时

需要看包的大小,有时可以下载下来,有时会卡住

pip3 --default-timeout=1000 install numpy


 

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...