python310: pip install Could not install packages (HTTPSConnectionPool)问题

一、问题描述

在使用pip install安装包或者升级pip版本(pip install --upgrade pip)时遇到以下错误:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/parsel/
Collecting parsel
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连 
接。', None, 10054, None))': /packages/85/7e/e3f1a7ff69303a4e08a8742a285406e5786650d8218ff194743eff292a1e/parsel-1.9.1-py2.py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001C819F2FE50>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')': /packages/85/7e/e3f1a7ff69303a4e08a8742a285406e5786650d8218ff194743eff292a1e/parsel-1.9.1-py2.py3-none-any.whl.metadata  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连 
接。', None, 10054, None))': /packages/85/7e/e3f1a7ff69303a4e08a8742a285406e5786650d8218ff194743eff292a1e/parsel-1.9.1-py2.py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连 
接。', None, 10054, None))': /packages/85/7e/e3f1a7ff69303a4e08a8742a285406e5786650d8218ff194743eff292a1e/parsel-1.9.1-py2.py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连 
接。', None, 10054, None))': /packages/85/7e/e3f1a7ff69303a4e08a8742a285406e5786650d8218ff194743eff292a1e/parsel-1.9.1-py2.py3-none-any.whl.metadata
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/85/7e/e3f1a7ff69303a4e08a8742a285406e5786650d8218ff194743eff292a1e/parsel-1.9.1-py2.py3-none-any.whl.metadata (Caused by NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001C819FAC430>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

在这里插入图片描述

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pip/

在这里插入图片描述

二、解决方案

配置pip.ini文件

1.文件管理器文件路径地址栏输入:%APPDATA% 回车,快速进入 C:\Users\电脑用户\AppData\Roaming 文件夹中
2、新建 pip 文件夹并在文件夹中新建 pip.ini 配置文件
在这里插入图片描述

3、新增 pip.ini 配置文件内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
extra-index-url = 
  http://mirrors.aliyun.com/pypi/simple
  http://pypi.douban.com/simple
  http://pypi.mirrors.ustc.edu.cn/simple
[install]
trusted-host=
  pypi.tuna.tsinghua.edu.cn
  mirrors.aliyun.com
  pypi.douban.com
  pypi.mirrors.ustc.edu.cn

查看配置结果:

pip config list -v

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/q1003675852/article/details/139647034