pip network_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
78%Fix Rate
85%Confidence
1Evidence
2023-01-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
pip 20.0+ active
Python 3.6-3.12 active

Root Cause

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

中文

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

Official Documentation

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

Workarounds

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

中文步骤

  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>

Dead Ends

Common approaches that don't work:

  1. 80% fail

    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% fail

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

  3. 65% fail

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