我一直试图通过阅读这里的不同答案来解决这个问题,但没有一个答案被证明是“解决方案”,所以我会尝试简要解释我的情况,以便你们可以给我一个线索。 问题是,当我尝试运行
pip install <package>
时,它会以以下警告开始(只是为了向您展示,使用 fastapi 作为示例):
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl
最后是:
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1,'[SSL:CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate(_ssl.c:1131)')))
我尝试的第一件事是
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package>
,但它只给了我另一个错误。所以我开始阅读有关 SSL 证书的内容,当错误显示“自签名证书”时,这意味着我尝试连接的服务器,他的证书是由服务器本身或提供链签名的实体自签名的不在浏览器的白名单中。
事实上也是如此!.
但是当我使用一些在线工具检查该网站的证书时一切似乎都很可靠
我上次下载软件包是大约一个月前(我昨天才意识到这一点)
venv
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org
<package-name>
例如:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org
pandas
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <package_name>
或永久:
pip config set global.trusted-host "pypi.org files.pythonhosted.org pypi.python.org"
如果遇到问题,最好的办法是创建一个 pip.ini 文件(Unix 上为 pip.conf)。您需要做的就是添加以下内容:
[global]
trusted-host = pypi.python.org
pypi.org
files.pythonhosted.org
如果您不确定在哪里可以找到 pip.ini 文件或如何创建它,请不要担心。有大量资源可以帮助您。只需查看 pip 配置文件,您就会找到所需的一切。点子配置