When using pip to install packages, sometimes the following problem occurs:

Could not fetch URL https://pypi.org/simple/pip/:  There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1018)'))) - skipping

This error message indicates that when trying to access https://pypi.org/simple/pip/, an SSL certificate verification failure occurred.

Specifically, the SSLCertVerificationError mentioned in the error message indicates that the client cannot verify the server's SSL certificate.

The solution is also simple: we can use a domestic mirror, such as the Tsinghua pip mirror.

Method 1: Temporary specification via command line

When installing Python packages, you can use the--index-urlparameter to specify the Tsinghua University mirror source, and use the--trusted-hostparameter to allow not using HTTPS.

The command is as follows:

pip install <package_name> --index-url http://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
  • --index-url: Specify the URL of the mirror source.
  • --trusted-host: Specify trusted hosts, allowing HTTPS to be disabled.

For example:

pip install baidusearch --index-url http://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn

Method 2: Global configuration

If you want to permanently set the Tsinghua University mirror source and not use HTTPS, you can do so by modifying the pip configuration file.

Configuration file path:

  • Windows:%APPDATA%\pip\pip.ini
  • macOS/Linux:~/.config/pip/pip.conf

Add the following content to the configuration file:

[global]
index-url = http://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

In this way, every time you use pip, it will automatically use the Tsinghua University mirror source and will not force the use of HTTPS.