欢迎访问星辰云IDC网站地图

pip 指定国内镜像,并设置不使用 https

作者:星辰云IDC编辑 阅读:7137

使用 pip 安装包,有时候会出现以下问题:

Could not fetch URL : There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='', 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

这个错误信息表明在尝试访问 时,遇到了 SSL 证书验证失败的问题。

具体来说,错误信息中提到的 SSLCertVerificationError 表示客户端无法验证服务器的 SSL 证书。

解决方法也很简单,我们可以使用国内镜像,比如清华的 pip 镜像。

方法 1:命令行临时指定

在安装 Python 包时,可以通过 --index-url 参数指定清华大学的镜像源,并通过 --trusted-host 参数允许不使用 HTTPS。

命令如下:

 pip install <package_name> --index-url --trusted-host .
  • --index-url:指定镜像源的 URL。
  • --trusted-host:指定信任的主机,允许不使用 HTTPS。

例如:

 pip install baidusearch --index-url --trusted-host .

方法 2:全局配置

如果你希望永久设置清华大学的镜像源,并且不使用 HTTPS,可以通过修改 pip 的配置文件来实现。了解更多信息,请访问:cloudblack

配置文件路径:

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

在配置文件中添加以下内容:

 [global] index-url = trusted-host = .

这样,每次使用 pip 时都会自动使用清华大学的镜像源,并且不会强制使用 HTTPS。

标签: pip 指定国内镜像 并设置不使用 https