Mac使用pip时持续出现SSL错误,重装系统及关防火墙无效求解决
Hey Sean, I feel your frustration—dealing with persistent SSL errors on pip even after reinstalling macOS and turning off the firewall is no fun. Let's walk through some targeted fixes that should help you get past this:
Upgrade pip using curl (bypass SSL for the upgrade)
Since the SSL error is blocking pip itself from updating, use curl to grab the official get-pip script and run it directly. This skips pip's broken SSL check temporarily to get you the latest version, which often fixes outdated TLS protocol issues:curl https://bootstrap.pypa.io/get-pip.py | python3Force pip to use trusted hosts
PyPI requires modern TLS connections, and older pip versions might struggle with certificate verification. Try running your install command with explicit trusted host flags:pip3 install discord.py --trusted-host pypi.org --trusted-host files.pythonhosted.orgAs a temporary workaround, you can also disable SSL verification entirely (use this only until you fix the root issue):
export PYTHONHTTPSVERIFY=0 pip3 install discord.pyCheck your system's SSL certificates
macOS relies on Keychain Access for trusted root certificates. Open Keychain Access, navigate to System > Certificates, and make sure you have up-to-date root certs like DigiCert Global Root CA and ISRG Root X1. If any are missing or expired:- Go to Keychain Access > Certificate Assistant > Get a Certificate From a Certificate Authority
- Follow the prompts to refresh your root certificates, or manually install any missing ones from Apple's official certificate repository.
Look for hidden network proxies
Even with the firewall off, leftover proxy settings (from a VPN, corporate network, or old configuration) can mess with SSL connections. Check for active proxies on your Wi-Fi (or Ethernet) interface:networksetup -getwebproxy Wi-Fi networksetup -getsecurewebproxy Wi-FiIf you see any enabled proxies, turn them off with:
networksetup -setwebproxystate Wi-Fi off networksetup -setsecurewebproxystate Wi-Fi offReinstall Python from the official source
The default Python bundled with macOS sometimes uses outdated SSL libraries. Download the latest Python version from python.org, run the installer, and make sure it updates your system PATH so you're using the newpython3andpip3instead of the system defaults. Verify this after installation:which python3 which pip3You should see paths pointing to
/Library/Frameworks/Python.framework/Versions/X.X/bin/(not/usr/bin/).
内容的提问来源于stack exchange,提问作者Sean Hatch

