You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pip安装失败(连接中断):遭遇HTTP/2.0未知协议错误

pip安装失败(连接中断):遭遇HTTP/2.0未知协议错误

问题描述

我最近测试pip安装时遇到了连接错误,以安装googletrans为例,执行命令后反复出现重试提示,最终安装失败。终端输出如下:

pip3 install googletrans
Defaulting to user installation because normal site-packages is not writeable
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', UnknownProtocol('HTTP/2.0'))': /simple/googletrans/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', UnknownProtocol('HTTP/2.0'))': /simple/googletrans/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', UnknownProtocol('HTTP/2.0'))': /simple/googletrans/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', UnknownProtocol('HTTP/2.0'))': /simple/googletrans/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', UnknownProtocol('HTTP/2.0'))': /simple/googletrans/
ERROR: Could not find a version that satisfies the requirement googletrans (from versions: none)
ERROR: No matching distribution found for googletrans

我原本预期会正常显示下载进度条,但完全无法完成安装。已经尝试过在虚拟环境中操作,问题依然存在。我的环境信息:

  • 系统:macOS
  • 编辑器:VSCode
  • Python版本:3.9
  • pip版本:24.2

解决办法

这种HTTP/2.0协议相关的连接错误,大多是因为pip新版本默认启用的HTTP/2协议和你的网络环境(比如公司防火墙、代理)不兼容导致的。给你几个亲测有效的解决方案:

  • 强制使用HTTP/1.1协议:直接通过环境变量禁用pip的HTTP/2支持,退回到兼容性更好的HTTP/1.1:

    PIP_NO_HTTP2=1 pip3 install googletrans
    

    如果用虚拟环境,激活venv后执行这条命令即可。

  • 更换国内PyPI镜像源:默认的PyPI源在部分网络环境下可能存在协议兼容问题,换成国内镜像源(比如清华镜像)试试:

    pip3 install googletrans -i https://pypi.tuna.tsinghua.edu.cn/simple
    

    若提示证书问题,可加上信任参数:--trusted-host pypi.tuna.tsinghua.edu.cn

  • 检查网络代理设置:如果是在公司网络下,确认是否有代理拦截了请求。需要代理的话,给pip加上代理参数:

    pip3 install googletrans --proxy http://你的代理IP:端口号
    

    不需要代理的话,关闭系统代理后再尝试安装。

备注:内容来源于stack exchange,提问作者Hypersonic Gridfin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 16:35:27