Pain Point
pip install hangs in WSL with no useful error, often after it starts fetching from files.pythonhosted.org.
The Rule
If DNS/connection to files.pythonhosted.org hangs but pypi.org works, suspect IPv6 preference + broken IPv6 routing.
Minimal Diagnosis
python -c "import urllib.request; print(urllib.request.urlopen('https://pypi.org/simple/').status)"
# expected: 200getent hosts pypi.org
# returns quicklygetent hosts files.pythonhosted.org
# may hangIf files.pythonhosted.org hangs, pip will hang. That host is where wheels and sdists are served from.
Fix
Prefer IPv4 for address selection using gai.conf:
sudo tee /etc/gai.conf >/dev/null <<'EOF'
precedence ::ffff:0:0/96 100
EOFThis does not disable IPv6. It changes the precedence so IPv4 is tried first.
Verify
getent hosts files.pythonhosted.org
# should return immediatelyThen retry:
pip install ipythonRevert
sudo tee /etc/gai.conf >/dev/null <<'EOF'
# empty override: use glibc defaults
EOFNotes
If you see multiple stuck installs, clear them before retrying:
pkill -f "python -u -m pip install" || true