【问题标题】:Could not install packages due to an EnvironmentError: Could not find a suitable TLS CA certificate bundle, invalid path由于 EnvironmentError 无法安装软件包:找不到合适的 TLS CA 证书包,路径无效
【发布时间】:2019-06-24 14:06:10
【问题描述】:

我收到此错误:

由于 EnvironmentError 无法安装软件包:找不到合适的 TLS CA 证书包,路径无效:/home/yosra/Desktop/CERT.RSA

当我跑步时:$ virtualenv venv

所以我在桌面上放了一个随机的 CERT.RSA 并创建了我的虚拟环境,但是当我运行时:pip install -r requirements.txt

我得到了这个:

由于 EnvironmentError 无法安装软件包:HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /KristianOellegaard/django-hvad/archive/2.0.0-beta.tar。 gz (由 SSLError(SSLError(0, 'unknown error (_ssl.c:3715)'),)) 引起

我觉得这两个错误是相互关联的,但我想知道如何解决第一个错误?

【问题讨论】:

  • @phd 它没有帮助,当我尝试安装 /usr/local/lib/python3.6/dist-packages/certifi/cacert.pem 时,我得到了同样的旧错误:ERROR: Could not install packages due to an EnvironmentError: Could not find a suitable TLS CA certificate bundle, invalid path: /home/yosra/Desktop/CERT.RSA

标签: python ssl pip


【解决方案1】:

如果您使用的是 Mac(我的是 10.13.6),请使用以下命令:

(security find-certificate -a -p ls /System/Library/Keychains/SystemRootCertificates.keychain &&        security find-certificate -a -p ls /Library/Keychains/System.keychain) > $HOME/.mac-ca-roots

然后用

修改.bashrc
export REQUESTS_CA_BUNDLE="$HOME/.mac-ca-roots"

那么做

$ source ~/.bashrc

【讨论】:

  • 对我不起作用(Mac 10.14.6)。如果它对你有用,你能解释一下这个命令的作用吗?
  • @AnumSheraz 缺少步骤,我修改了答案。你能再试一次看看有没有帮助?它修复的错误是SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)
  • 试过了,但我的用户没有“.bashrc”所以我现在不能用这个方法修复它。
  • 为我工作。我有 macOS 11.5.2
  • @MatthewHarris 任何 shell 配置文件都应该可以正常工作。
【解决方案2】:

在 Windows 10 中, 1.通过以下命令找到certifi的位置,检查是否已经安装

import certifi
certifi.where()
  1. 记下cacert.pem文件的路径

  2. 在 Windows 资源管理器中搜索 pip.ini 文件并在记事本中编辑该文件并设置 path = <file path of cacert.pem >

【讨论】:

  • 通过运行命令pip config -v list查找所有可能的pip.ini文件
【解决方案3】:

您需要允许 pip 引用正确的证书。先检查证书;

python -c "import certifi; print(certifi.where())"

那就先手动测试一下;

pip install -r requirements.txt --cert=<the above certificate path>

如果一切正常,则在位于 $HOME/.pip/pip.conf 的 pip.conf 文件(或 Windows 上的 %APPDATA%\pip\pip.ini)上更新此路径。例如

[global]
cert = /usr/local/share/ca-certificate/mycert.crt

【讨论】:

    【解决方案4】:

    我在 Pycharm 中以“pip install flask”的形式运行命令时收到此错误。

    如果您查看错误,您会看到错误指向“packages due to an EnvironmentError: Could not find a suitable TLS CA certificate bundle -- Invalid path”。

    我通过删除环境变量“REQUESTS_CA_BUNDLE”解决了这个问题,或者您可以将环境变量“REQUESTS_CA_BUNDLE”的名称更改为其他名称。

    重启你的 Pycharm 应该可以解决这个问题。

    谢谢!

    【讨论】:

      猜你喜欢
      • 2019-02-27
      • 2019-03-27
      • 2019-01-08
      • 2022-01-02
      • 2021-08-09
      • 2023-04-03
      • 2018-08-12
      • 2019-06-07
      • 2018-11-10
      相关资源
      最近更新 更多