升级最新Python后用pip安装包遇SSL证书错误求助
Hey there, let's break down what's happening with your pip issues and fix them step by step. From your error traceback, it looks like you're accidentally using Python 2.7's pip even though you upgraded to the latest Python version—plus the old SSL certificate error is lingering. Here's how to tackle both problems:
1. Make Sure You're Using the Correct Pip (For Your New Python Version)
Your error log shows pip is running from Python 2.7's directory (/Library/Frameworks/Python.framework/Versions/2.7/...), which means your terminal is still prioritizing the old Python installation. Let's fix that:
- First, verify which Python/pip versions you're currently using:
python --version pip --version - If they show Python 2.7, switch to your new Python's pip (usually
pip3for Python 3, or a version-specific alias likepip3.11):python3 --version pip3 --version - To make this the default, add aliases to your shell config file (e.g.,
~/.zshrcfor Zsh,~/.bash_profilefor Bash):
Save the file, then restart your terminal or runalias python='python3' alias pip='pip3'source ~/.zshrc(replace with your config path) to apply the changes.
2. Resolve the SSL Certificate Error
SSL issues usually stem from outdated pip versions or missing system certificates. Here's how to fix them:
- First, upgrade pip to the latest version (this fixes most TLS/SSL compatibility issues):
pip3 install --upgrade pip - If you still get SSL errors when installing packages, bypass certificate checks temporarily (note: this is insecure for untrusted sources, only use for PyPI):
pip3 install your-package-name --trusted-host pypi.org --trusted-host files.pythonhosted.org - If you must use Python 2.7's pip (strongly discouraged—Python 2 is end-of-life), install the last compatible pip version and use the trusted host flag:
pip2 install --upgrade pip==20.3.4 pip2 install your-package-name --trusted-host pypi.org --trusted-host files.pythonhosted.org
3. Fix System Root Certificate Issues (If All Else Fails)
Sometimes SSL errors happen because your system's root certificates are outdated or missing:
- On macOS, update your root certificates via Homebrew:
brew install ca-certificates - Then tell pip to use the updated certificates when installing packages:
pip3 install your-package-name --cert /usr/local/etc/openssl/cert.pem
内容的提问来源于stack exchange,提问作者david

