pip install fails with "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"

This error message occurs when pip is unable to verify the certificate of the website it is trying to connect to. This can happen for a number of reasons, including an out-of-date certificate on the server, a problem with the certificate chain, or an issue with the client machine's certificate store.

A common solution to this problem is to use the --trusted-host option with pip to explicitly trust the host in question. For example, if you are trying to install a package from pypi.org, you can use the following command to install it:

pip install --trusted-host pypi.org <package-name>

This tells pip to trust packages from the pypi.org domain, and should allow the installation to proceed.

Watch a course Python - The Practical Guide

Alternatively, If the issue persist, you could try the following command to ignore SSL verification

pip install --trusted-host pypi.org --ignore-installed <package-name>

This tells pip to ignore SSL verification

It is worth noting that this option can also be used to add specific trusted hosts to a pip configuration file, which can be useful if you need to install multiple packages from the same untrusted host. You can also try to upgrade pip to the latest version using

python -m pip install --upgrade pip

You can also use the --cert option to specify a CA_BUNDLE file or directory with certificates of trusted CAs

pip --cert path/to/CA_BUNDLE install package_name

Please be aware that disabling verification like this opens you up to potential security risks and should be used with caution.