The error "ConnectionError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"
occurs when pip
is unable to verify the SSL certificate of the repository from which it is trying to download a package. This can happen for several reasons, including an outdated or misconfigured CA certificates bundle or network issues. Below are several ways to resolve this issue.
Solution 1: Upgrade pip
Ensure that you have the latest version of pip
, as older versions may have issues with SSL certificates.
python -m pip install --upgrade pip
Solution 2: Add the Trusted Host Option
If you're certain that the repository you are connecting to is trustworthy, you can bypass SSL certificate verification by adding the --trusted-host
option:
pip install <package_name> --trusted-host pypi.org --trusted-host files.pythonhosted.org
For example:
pip install requests --trusted-host pypi.org --trusted-host files.pythonhosted.org
Solution 3: Install the certifi
Package and Use it with pip
The certifi
package provides Mozilla's CA Bundle in Python. You can use this to ensure that pip
uses the correct CA certificates.
Install
certifi
:pip install certifi
Locate the path to
certifi
’s certificate:python -m certifi
Export the
SSL_CERT_FILE
environment variable to point to thecertifi
certificate bundle:On Windows:
set SSL_CERT_FILE=C:\\path\\to\\cacert.pem
- On **Linux/macOS**:
```bash
export SSL_CERT_FILE=/path/to/cacert.pem
```
Run
pip
again:pip install <package_name>
Solution 4: Manually Update certifi
Certificate
If the issue persists, you can manually update the certificates used by pip
.
- Download the latest
cacert.pem
file from the certifi GitHub repository. - Replace the existing
cacert.pem
file in your Python installation'scertifi
directory with the newly downloaded file. The directory can typically be found here:- Windows:
C:\\PythonXX\\Lib\\site-packages\\certifi
- macOS/Linux:
/usr/local/lib/pythonX.X/site-packages/certifi
- Windows:
Solution 5: Disable SSL Verification (Temporary Solution)
As a last resort, you can disable SSL verification entirely. This is generally not recommended due to the security implications.
- Create or edit the
pip.conf
file:- Windows:
%APPDATA%\\pip\\pip.ini
- Linux/macOS:
~/.pip/pip.conf
or~/.config/pip/pip.conf
- Windows:
Add the following lines:
[global] trusted-host = pypi.org disable-pip-version-check = true
Try running
pip install
again.
Solution 6: Ensure System Time is Correct
Sometimes SSL errors occur if your system's date and time are incorrect. Make sure your system time is accurate and synchronized with a time server.
Summary
The SSL verification error with pip
is typically due to issues with certificate verification. You can resolve it by updating pip
, configuring the trusted-host
option, using the certifi
package, or as a last resort, disabling SSL verification. Each method has different security implications, so it's important to choose the one that best fits your situation.
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github