pip network_error ai_generated true

错误:由于连接错误无法安装包:[错误号 104] 对端重置连接

ERROR: Could not install packages due to a ConnectionError: [Errno 104] Connection reset by peer

ID: pip/network-connection-reset-by-peer

其他格式: JSON · Markdown 中文 · English
78%修复率
85%置信度
1证据数
2023-01-20首次发现

版本兼容性

版本状态引入弃用备注
pip 20.0+ active
Python 3.6-3.12 active

根因分析

到 PyPI 服务器或镜像的 TCP 连接被远程主机突然关闭,通常是由于防火墙规则、负载均衡器超时或网络不稳定。

English

The TCP connection to the PyPI server or mirror is abruptly closed by the remote host, typically due to firewall rules, load balancer timeouts, or network instability.

generic

官方文档

https://pip.pypa.io/en/stable/topics/network/

解决方案

  1. Use a different PyPI mirror with retries: pip install --index-url https://pypi.tuna.tsinghua.edu.cn/simple --retries 5 <package>
  2. Increase the socket timeout to avoid premature resets: pip install --default-timeout=120 <package>
  3. Use pip's --proxy option if behind a corporate proxy: pip install --proxy http://user:pass@proxy:8080 <package>

无效尝试

常见但无效的做法:

  1. 80% 失败

    The network condition is transient but repeating the exact same request often hits the same reset due to caching or persistent firewall state.

  2. 50% 失败

    Overly aggressive and may expose the system to security risks; the issue may be on the server side, not local.

  3. 65% 失败

    VPNs can introduce additional latency or packet loss, making the connection reset more likely.