如何在安装库时使PyCharm忽略SSL错误?

问题描述 投票:3回答:1

我正在尝试在使用自签名SSL证书的公司网络上将requests库安装到PyCharm中的Python环境中。因此,使用File > Settings > Project > Project Interpreter > Install安装库时会出现HTTPS错误:

Collecting requests
  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection
    broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.
    VerifiedHTTPSConnection object at 0x0368D5D0>: Failed to establish a new connection:
    [Errno 11003] getaddrinfo failed',)': /simple/requests/
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests

我尝试通过将pip添加到我的安装选项来使--cert C:\COMPANY-CAROOT.pem信任我公司的根证书,这被解释为:

pip install --cert C:\COMPANY-CAROOT.pem requests

我也尝试打开File > Settings > Project > Server Certificates并自动检查接受不受信任的证书,但遇到了同样的问题。

在安装外部库时,如何让PyCharm忽略SSL证书错误?

python pip pycharm ssl-certificate
1个回答
0
投票

我遇到了同样的问题。我解决它的方法是在txt文件中添加我想要安装的所有软件包,例如包含所有软件包名称及其版本的requiements.txt。

然后从终端(也可以是PyCharm终端),我做了:

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -r requirements.txt

这里的关键是使用--trusted-host。在文件中添加包只是为了方便。或者,您可以创建一个pip.ini文件并在那里添加可信主机。

希望这可以帮助 :)

© www.soinside.com 2019 - 2024. All rights reserved.