How to Fix pip SSL: CERTIFICATE_VERIFY_FAILED Error
In this tutorial, you'll learn about How to Fix pip SSL: CERTIFICATE_VERIFY_FAILED Error. We cover key concepts, practical examples, and best practices.
The Problem
You run pip install <package> and get Could not fetch URL https://pypi.org/simple/... There was a problem confirming the ssl certificate: CERTIFICATE_VERIFY_FAILED. pip cannot verify the SSL certificate of PyPI or your private registry. This happens when CA certificates are outdated, a proxy intercepts HTTPS traffic, or Python's bundled certificates don't match your system's, which is common on macOS after a Python upgrade.
Quick Fix
1. Bypass SSL verification (temporary workaround)
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <package>
This skips certificate verification for those hosts. Use only as a temporary workaround while you fix the underlying issue.
2. Update CA certificates on Linux
# Ubuntu / Debian
sudo apt-get update && sudo apt-get install --reinstall ca-certificates
# RHEL / CentOS / Fedora
sudo yum reinstall ca-certificates
3. Update certifi in Python
pip install --upgrade certifi
The certifi package provides Mozilla's CA bundle. An outdated certifi is the most common cause on macOS and Windows.
4. Fix on macOS
# If Python was installed from python.org
open /Applications/Python\ 3.x/Install\ Certificates.command
# Or manually update certifi
pip3 install --upgrade certifi
5. Set pip config to use a trusted host
pip config set global.trusted-host pypi.org
pip config set global.trusted-host files.pythonhosted.org
This persists the setting across all pip commands.
6. Use a custom CA bundle
pip install --cert /path/to/custom-ca-bundle.crt <package>
Or set the environment variable for all HTTP requests:
export REQUESTS_CA_BUNDLE=/path/to/custom-ca-bundle.crt
export SSL_CERT_FILE=/path/to/custom-ca-bundle.crt
7. Test the fix
python3 -c "import urllib.request; print(urllib.request.urlopen('https://pypi.org').status)"
If it returns 200, pip should work now.
Common Causes
| Cause | When It Happens | Fix |
|---|---|---|
Outdated certifi |
After Python upgrade | pip install --upgrade certifi |
| Missing system CA certs | Fresh Linux install | sudo apt-get install --reinstall ca-certificates |
| Corporate proxy/SSL inspection | Behind corporate firewall | Use --cert /path/to/corporate-bundle.crt |
| macOS Python installer | Using python.org installer | Run Install Certificates.command |
Prevention
- Keep
ca-certificatesandcertifiupdated:pip install -U certifiafter every Python upgrade - Use
pip config set global.cert /path/to/bundleto point to your corporate CA bundle - Run
pip install -U certifiperiodically, especially after Python upgrades on macOS - If using a corporate proxy, request the CA bundle from your IT team and configure pip to trust it permanently
- Use
python3 -c "import ssl; print(ssl.get_default_verify_paths())"to verify which CA bundle your Python is using
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro