The pip client is failing to connect to package repositories due to its inability to verify the SSL certificate presented by the server.
This is almost always caused by one of the following:
-
Outdated
pipversion: Older versions ofpipmight not have the latest root certificates or might use older, less secure TLS versions that are no longer supported by repositories.- Diagnosis: Run
pip --version. If it’s older than 20.0, this is a prime suspect. - Fix: Upgrade
pipitself.
This works because the newpython -m pip install --upgrade pippipbinary will include updated certificate bundles and support for modern TLS protocols.
- Diagnosis: Run
-
System-level certificate store issues: Your operating system or Python installation might have a corrupted or incomplete CA (Certificate Authority) bundle.
pipoften relies on these system-level certificates.- Diagnosis: Try installing a known-good, simple package directly. If that fails with the same SSL error, it points to the system store. You can also try
openssl s_client -connect pypi.org:443 -showcertsto see what certificates your system is presenting. - Fix: Reinstalling Python or updating your OS’s CA certificates can resolve this. On Debian/Ubuntu:
sudo apt-get update && sudo apt-get install --reinstall ca-certificates. On macOS with Homebrew:brew update && brew upgrade ca-certificates. For Python installed via pyenv, you might need to recompile Python after updating system CAs. This fixes it by ensuringpiphas access to a trusted, complete set of root certificates.
- Diagnosis: Try installing a known-good, simple package directly. If that fails with the same SSL error, it points to the system store. You can also try
-
Network proxy or firewall interference: Corporate proxies or firewalls that perform SSL inspection (man-in-the-middle) can break
pip’s certificate verification if they present their own certificate thatpipdoesn’t trust.- Diagnosis: If you’re on a corporate network, this is highly likely. Try from a different network (e.g., home Wi-Fi, mobile hotspot) to confirm.
- Fix: You can tell
pipto trust a specific CA certificate provided by your proxy.
If your proxy uses its own certificate, you can pointpip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>pipto it:
Thepip install --cert /path/to/your/proxy.crt <package_name>--trusted-hostflag bypasses verification for the specified hosts, and--certexplicitly tellspipwhich certificate to trust, allowing it to establish a secure connection through the proxy.
-
Incorrect
PIP_CERTenvironment variable: If you’ve previously setPIP_CERTto a specific certificate file or directory, and that file is now missing, incorrect, or outdated,pipwill fail.- Diagnosis: Check your environment variables.
echo $PIP_CERT - Fix: Unset the variable or point it to the correct certificate file.
Or, if you intend to use a specific certificate:unset PIP_CERT # On Linux/macOS # or set PIP_CERT= # On Windows CMD $env:PIP_CERT=$null # On PowerShell
This fixes it by either removing the incorrect instruction or providingexport PIP_CERT=/path/to/your/correct/certificate.pempipwith the correct certificate file it needs for verification.
- Diagnosis: Check your environment variables.
-
ssl_no_verifyoption inpip.conf: Similar to the environment variable, an explicit configuration inpip.confmight be causing issues.- Diagnosis: Check your
pip.conffile. Common locations are~/.config/pip/pip.confor~/.pip/pip.conf. Look forssl_no_verify = trueor acert =directive that is no longer valid. - Fix: Remove or comment out the problematic line. For example, if you find
ssl_no_verify = true, change it to# ssl_no_verify = trueor delete the line. If there’s acert =line, ensure the path is correct or remove it if you wantpipto use the default system store. This correctspip’s behavior by stopping it from ignoring SSL verification or by pointing it to the correct certificate if one was specified.
- Diagnosis: Check your
-
Time synchronization issues: If your system clock is significantly out of sync with the current time, certificates that are valid for a specific date range will appear expired or not yet valid.
- Diagnosis: Check your system’s date and time.
date - Fix: Synchronize your system clock with an NTP server. On most Linux systems:
Or manually set the time if necessary. This ensures that certificate validity periods are evaluated correctly against the current time.sudo systemctl start systemd-timesyncd sudo systemctl enable systemd-timesyncd
- Diagnosis: Check your system’s date and time.
After resolving these, the next error you’ll likely encounter is a FileNotFoundError if you try to install a package that has been removed from PyPI.