How to Fix pip ReadTimeoutError When Installing Packages
In this tutorial, you'll learn about How to Fix pip ReadTimeoutError When Installing Packages. We cover key concepts, practical examples, and best practices.
The Problem
pip install fails with ReadTimeoutError or SSL: TLSV1_ALERT_INTERNAL_ERROR when downloading packages. This happens when the connection to PyPI is slow, the default 15-second timeout is too short, or the CDN endpoint is far from your location.
Quick Fix
Step 1: Increase the default timeout
Use the --timeout flag to give each download more time:
pip install --timeout 60 pandas
This sets the per-connection timeout to 60 seconds instead of the default 15.
Step 2: Use a PyPI mirror closer to you
Speed up downloads by using a geographically closer mirror:
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
For users in Europe, use the official mirror:
pip install pandas -i https://mirrors.aliyun.com/pypi/simple/
Step 3: Upgrade pip itself
Older pip versions have known timeout and SSL issues:
pip install --upgrade pip
Successfully installed pip-24.0
Step 4: Set timeout globally in pip config
Make the timeout persistent across all pip commands:
pip config set global.timeout 60
Verify the setting:
pip config list
global.timeout='60'
Step 5: Retry with --default-timeout for large packages
For very large packages like PyTorch or TensorFlow:
pip install --default-timeout=120 torch torchvision
Alternative Solutions
Use a requirements file with index-url
Specify a mirror globally for a project:
# requirements.txt
--index-url https://mirrors.aliyun.com/pypi/simple/
pandas
numpy
Use pip download for offline installation
Download packages once and install from cache:
pip download -r requirements.txt -d ./pkg_cache
pip install --no-index --find-links ./pkg_cache -r requirements.txt
Common Mistakes to Avoid
Installing large packages without --timeout. PyTorch, TensorFlow, and similar large packages often exceed the default 15-second timeout. Use --timeout 120.
Not using a PyPI mirror in regions far from the US. Users in Asia or South America benefit significantly from regional mirrors.
Running pip install behind a slow VPN. Corporate VPNs can slow download speeds. Use --proxy if you need to route through a corporate proxy.
Pro Tips
Use pip config set for persistent settings. Set timeout, index URL, and trusted hosts globally with pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/.
Use pip download --no-deps for faster caching. Download packages without resolving dependencies for a faster offline install later.
Check your network speed first. Before increasing timeout, test your connection to PyPI with curl -o /dev/null -s -w %{speed_download} https://pypi.org/simple/pip/.
Use a local PyPI proxy for team environments. Tools like devpi or bandersnatch create a local mirror that eliminates network timeouts entirely for all team members.
Use pip install --prefer-binary to avoid compilation timeouts. For packages with native extensions, prefer binary wheels: pip install --prefer-binary pandas.
Prevention
- Keep pip updated with
pip install --upgrade pip. - Use a PyPI mirror close to your geographic region.
- Set a global timeout of 60 seconds with
pip config set global.timeout 60.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro