How to Solve ReadTimeoutError: HTTPSConnectionPool with pip Package Installation

Nov 23, 2025 · Programming · 14 views · 7.8

Keywords: pip | ReadTimeoutError | timeout solution

Abstract: This article provides an in-depth analysis of the ReadTimeoutError: HTTPSConnectionPool timeout error that occurs during pip package installation in Python. It explains the underlying causes, such as network latency and server issues, and presents the core solution of increasing the timeout using the --default-timeout parameter. Additional strategies, including using mirror sources, configuring proxies, and upgrading pip, are discussed to ensure reliable package management. With detailed code examples and configuration guidelines, the article helps readers effectively resolve network timeout problems and enhance their Python development workflow.

Error Phenomenon and Cause Analysis

When installing Python packages with pip, users often encounter the ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. error. This error indicates that pip failed to download packages from the PyPI server due to a network connection timeout. Specifically, when pip sends an HTTPS request to pypi.python.org, if no response is received within the default timeout period, this exception is raised.

The error stack trace shows that the issue originates in the read method of urllib3/response.py, where a ReadTimeoutError is thrown upon timeout. This is typically caused by network latency, high server load, or firewall restrictions. In the example, the user faced this error while installing packages like future, scikit-learn, numpy, and scipy, even with sudo privileges, indicating that the root cause is network-related rather than a permission issue.

Core Solution: Increasing Timeout Duration

To address network timeout issues, the most direct and effective solution is to increase pip's timeout duration. Pip provides the --default-timeout parameter, which allows users to customize the connection and read timeout thresholds. By default, pip's timeout is relatively short and may be insufficient for poor network conditions. Setting this parameter to a higher value, such as 100 seconds, can significantly reduce the likelihood of timeout errors.

Specifically, add the --default-timeout=100 parameter to the pip install command. For example, to install the future package, use the following command:

sudo pip install --default-timeout=100 future

Here, --default-timeout=100 sets the timeout to 100 seconds, ensuring that downloads can complete even in slow network environments. If 100 seconds is still insufficient, the value can be increased further, such as to 200 or 300 seconds, based on actual conditions. However, note that excessively long timeouts may cause prolonged waits in case of genuine network failures, so it is advisable to set a reasonable value according to the network status.

Additional Supplementary Solutions

Besides adjusting the timeout, several other methods can help mitigate pip network timeout problems:

Error Handling and Debugging Suggestions

When a timeout error occurs, first check if the network connection is stable, for example, by pinging pypi.python.org to test reachability. If the network is unreachable, address network configuration issues. Additionally, review pip's debug logs, typically located at /root/.pip/pip.log, which may contain more detailed error information to help identify the root cause.

For production environments, it is recommended to write timeout settings and mirror source configurations into pip's configuration file (e.g., ~/.pip/pip.conf) to avoid manual parameter entry each time. For example, add the following to the configuration file:

[global] timeout = 100 index-url = https://pypi.tuna.tsinghua.edu.cn/simple

This ensures that all pip commands automatically apply these settings, improving efficiency and reducing errors.

Conclusion

The ReadTimeoutError: HTTPSConnectionPool error is a common issue in pip package installations, primarily caused by network timeouts. By increasing the --default-timeout parameter, using mirror sources, or configuring proxies, this problem can be effectively resolved. In practice, selecting the appropriate method based on network conditions and utilizing configuration files for persistent settings can significantly enhance the stability and efficiency of Python package management. If issues persist, consider checking system network settings or consulting a network administrator.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.