Mac系统使用pip install时SSL证书验证失败问题求助
fake-useragent via Pip Hey there, let's tackle this SSL handshake issue you're hitting with fake-useragent—I've run into similar problems before, so I know how frustrating it can be when basic pip installs go sideways. That tlsv1 alert protocol version error is telling us your system is trying to connect using an outdated TLS protocol (like TLS 1.0/1.1) that the target server no longer supports. Most modern PyPI mirrors and data sources for fake-useragent now require TLS 1.2 or newer.
Here are the step-by-step fixes, ordered by how sustainable they are:
1. Upgrade Pip to the Latest Version
Old versions of pip default to using outdated TLS protocols. Upgrading pip should fix this for most cases:
- Run this command in your terminal:
python -m pip install --upgrade pip - If you still get SSL errors during the pip upgrade, bypass the SSL check temporarily (only for this step) with:
python -m pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org
2. Upgrade Your Python Version
If you're using Python 2.7, 3.4, or older, these versions come with SSL libraries that don't support TLS 1.2+. This is the root cause for many users facing this issue.
- Install a stable, supported Python version (3.7 or newer) — this will resolve the problem long-term and prevent similar compatibility issues with other packages.
3. Temporarily Bypass SSL Verification (Emergency Fix)
Only use this if you need a quick fix and can't upgrade pip/Python right now (note: this has security risks, so don't make it a habit):
- Install
fake-useragentwith trusted hosts specified:pip install fake-useragent --trusted-host pypi.org --trusted-host files.pythonhosted.org - Alternatively, disable SSL verification for the session by setting an environment variable first:
- On Linux/macOS:
export PYTHONHTTPSVERIFY=0 pip install fake-useragent - On Windows (Command Prompt):
set PYTHONHTTPSVERIFY=0 pip install fake-useragent
- On Linux/macOS:
4. Fix fake-useragent's Data Fetching SSL Issue
Sometimes the error isn't from pip itself, but from fake-useragent trying to pull user-agent data from an external site after installation. To work around this:
- Manually obtain the
useragents.jsonfile (the official one used by the package) and save it to your local machine. - Set an environment variable pointing to this file before installing:
- On Linux/macOS:
export FAKE_USERAGENT_JSON=/path/to/your/useragents.json pip install fake-useragent - On Windows:
set FAKE_USERAGENT_JSON=C:\path\to\your\useragents.json pip install fake-useragent
- On Linux/macOS:
Pick the fix that makes the most sense for your setup—upgrading Python/pip is always the best long-term solution to avoid similar issues down the line.
内容的提问来源于stack exchange,提问作者christopher de jesus

