gpt4 book ai didi

python - Python 中的 SSL 模块不可用(在 OSX 上)

转载 作者:太空宇宙 更新时间:2023-11-03 12:41:08 25 4
gpt4 key购买 nike

我在 OSX 10.13 上的 virtualenv 中运行 pip install 时遇到问题。我已经运行了 brew install openssl 并且路径 /usr/local/include/openssl 指向 ../opt/openssl/include/openssl。有谁知道如何解决这一问题?在我使用 brew install 重新安装 python 后开始出现这种情况。

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting Pillow Could not fetch URL https://pypi.python.org/simple/pillow/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping Could not find a version that satisfies the requirement Pillow (from versions: ) No matching distribution found for Pillow

更新:这里有更多信息:

✗ which python
/usr/local/opt/python/libexec/bin/python
✗ which pip
/usr/local/opt/python/libexec/bin/pip
✗ python --version
Python 3.7.4
✗ pip --version
pip 19.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
✗ brew info python
python: stable 3.7.4 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.6.5_1 (4,795 files, 100.0MB)
Poured from bottle on 2019-10-08 at 14:39:37
/usr/local/Cellar/python/3.7.4_1 (3,903 files, 60.6MB) *
Poured from bottle on 2019-10-08 at 14:37:10
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb

是的,我同时安装了 3.6.5_1 和 3.7.4_1,因为有时我可能需要在两者之间切换。

✗ brew unlink openssl
Unlinking /usr/local/Cellar/openssl/1.0.2s... 0 symlinks removed

最佳答案

ssl 模块及其底层 C 扩展似乎是 python 公式的一部分:

Mac-Admin:~ admin$ python3
Python 3.7.4 (default, Sep 7 2019, 18:27:02)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl
<module 'ssl' from '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py'>
>>> import _ssl
>>> _ssl
<module '_ssl' from '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_ssl.cpython-37m-darwin.so'>

所以它丢失很可能意味着软件包安装损坏,brew reinstall python 应该修复。


另请注意,虽然 Homebrew 允许多个版本共存,its installation logic isn't quite designed to keep the alternative versions operational除非它们是通过版本化公式安装的(例如,在常规 brew cleanup 中定期删除旧版本)。

因此,如果您需要定期在 Python 版本之间切换,请考虑使用 pyenv(也可以通过 brew 获得)——或者一些为其提供版本化公式的第 3 方 tap .

关于python - Python 中的 SSL 模块不可用(在 OSX 上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58280484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com