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

- **ID:** `pip/network-connection-reset-by-peer`
- **领域:** pip
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

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

## 版本兼容性

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

## 解决方案

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>
   ```

## 无效尝试

- **** — The network condition is transient but repeating the exact same request often hits the same reset due to caching or persistent firewall state. (80% 失败率)
- **** — Overly aggressive and may expose the system to security risks; the issue may be on the server side, not local. (50% 失败率)
- **** — VPNs can introduce additional latency or packet loss, making the connection reset more likely. (65% 失败率)
