pip安装时持续连接本地机器超时,求助解决方法
Hey there, sorry to hear you've been stuck on this frustrating pip issue for two days—let's break down what's happening and fix it step by step.
The error makes it clear pip is trying to connect to your local machine (192.168.0.8) instead of the official PyPI server. This usually means your pip configuration, system settings, or a local service is redirecting PyPI requests to your local IP. Here are the most reliable fixes to try:
1. Reset pip's Package Source Configuration
Pip might be configured to use a local package index that's no longer running. Let's check and fix this:
- On Windows: Open
%APPDATA%\pip\pip.ini(if the file exists) - On Linux/macOS: Open
~/.config/pip/pip.confor~/.pip/pip.conf - Look for lines like
index-url = http://192.168.0.8/simple/pointing to your local IP. Replace them with a valid public PyPI source, for example:
If you're in China, a faster domestic mirror works too:[global] index-url = https://pypi.org/simple/[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
2. Install six with a Temporary Public Source
To bypass your current config and test if the issue is source-related, run this command directly:
pip install six -i https://pypi.org/simple/
If this works, your pip config was definitely the problem—stick with the fix from step 1.
3. Check Your System's Hosts File
Your hosts file might be redirecting PyPI domains to your local IP by mistake:
- Windows: Open
C:\Windows\System32\drivers\etc\hostswith admin privileges - Linux/macOS: Open
/etc/hostsusing sudo - Look for entries like
192.168.0.8 pypi.orgor192.168.0.8 simple.pypi.org. If found, comment them out by adding a#at the start of the line, then save the file.
4. Disable Unintended Proxy Settings
Pip or your system could be using a proxy that points to your local machine:
- Check pip's proxy config: Run
pip config get proxy. If it returns a value pointing to 192.168.0.8, unset it with:pip config unset proxy - Check system environment variables: Look for
HTTP_PROXYorHTTPS_PROXYset tohttp://192.168.0.8:.... Temporarily unset them (restart your terminal after doing this) and try installing again.
5. Check for Local Services Intercepting Traffic
If you've ever set up a local PyPI mirror, VPN, or firewall tool that routes package requests locally, make sure those services are running (if you intend to use them) or temporarily disable them. Tools like local proxy servers or security software can sometimes redirect traffic unexpectedly.
Give these steps a go—one of them should resolve the timeout issue. Let me know if you hit any snags along the way!
内容的提问来源于stack exchange,提问作者flying 8lack

