macOSX(Python2.7.10)用pip9.0.1安装库遇连接错误求助
Hey there, let's work through that frustrating connection error you're hitting when trying to install Flask with pip 9.0.1. That Errno 61: Connection refused message typically means pip can't reach PyPI's default servers—and with older versions of pip/Python, this is pretty common due to network restrictions, outdated HTTPS support, or regional blocks.
Here are the most reliable fixes to try:
Test your network access to PyPI first
Run this command in your terminal to check if you can reach the Flask package index directly:curl https://pypi.org/simple/flask/If you get a connection error here too, your issue is likely a network firewall, proxy requirement, or regional block. If it loads fine, the problem is specific to pip's configuration.
Use a domestic PyPI mirror temporarily
Older pip versions often struggle with the default PyPI server's HTTPS setup. Try installing Flask using a trusted mirror instead:pip install flask -i https://pypi.tuna.tsinghua.edu.cn/simpleThis bypasses the default server and uses a faster, more accessible mirror for many regions.
Set up the mirror permanently (for future installs)
To avoid typing the mirror URL every time, create a pip config file:- Make the
.pipdirectory in your home folder if it doesn't exist:mkdir -p ~/.pip - Create or edit
~/.pip/pip.confwith this content:[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Now all pip installs will use this mirror by default.
- Make the
Upgrade pip to the latest compatible version
Pip 9.0.1 is pretty old, and newer versions have better network handling (even for Python 2.7). Since Python 2.7 is end-of-life, the last pip version that supports it is 20.3.4. Upgrade with:pip install --upgrade pip==20.3.4After upgrading, try installing Flask again with the regular
pip install flaskcommand.Check for proxy settings
If your network requires a proxy to access external sites, you need to tell pip about it. Install Flask with your proxy details:pip install flask --proxy http://your-proxy-address:portFor permanent proxy setup, add these lines to your
~/.pip/pip.conf:[global] proxy = http://your-proxy-address:port
A quick note: Python 2.7 has been officially unsupported since 2020, so if you have the option, consider migrating to Python 3.x for better security and package support. But if you're stuck with 2.7 for now, the above steps should get you past the connection error.
内容的提问来源于stack exchange,提问作者user1919

