如何解决macOS pyenv:pip 安装不起作用 [SSL:CERTIFICATE_VERIFY_FAILED]
我正在尝试使用 pip 安装 numpy 包,同时使用 pyenv(全球版本 3.8.6)。
命令:
pip install numpy
输出:
WARNING: Retrying (Retry(total=4,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 in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=3,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=2,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=0,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
Could not fetch URL https://pypi.org/simple/numpy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org',port=443): Max retries exceeded with url: /simple/numpy/ (Caused by SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))) - skipping
ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy
我试图解决这个问题的方法:
- 使用
brew reinstall openssl
重新安装 openssl - 使用
brew reinstall pyenv
重新安装 pyenv - 使用
brew reinstall pyenv-virtualenv
重新安装 pyenv-virtualenv
当我尝试通过从 eval "$(pyenv init -)"
中删除 eval "$(pyenv virtualenv-init -)"
和 ~/.bash_profile
来禁用 pyenv 时,它工作正常,因为它使用系统 Python 版本。
短期解决方案是添加 --trusted-host pypi.org
标志,但我不确定为什么没有标志它不能工作。
请帮忙!
解决方法
如here所示,在以前的 Python 版本中,Apple 提供了 OpenSSL 包,但现在不再提供。
为了临时修复,在使用 pip 时将 pypi.org 添加为受信任的主机(pythonhosted.org 实际上托管文件,但它们是从 pypi 下载的,因此它们也被添加到受信任的主机中):
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools
要获得更永久的修复,请安装证书和 Scrapy:
pip install certifi
pip install Scrapy
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。