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 certifiLocate the path to
certifi’s certificate:python -m certifiExport the
SSL_CERT_FILEenvironment variable to point to thecertificertificate 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
pipagain: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.pemfile from the certifi GitHub repository. - Replace the existing
cacert.pemfile in your Python installation'scertifidirectory 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.conffile:- Windows:
%APPDATA%\\pip\\pip.ini - Linux/macOS:
~/.pip/pip.confor~/.config/pip/pip.conf
- Windows:
Add the following lines:
[global] trusted-host = pypi.org disable-pip-version-check = trueTry running
pip installagain.
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.