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

2024-06-12 19:45:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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

Tags: installpipthefromhttpsisversionusr
1条回答
网友
1楼 · 发布于 2024-06-12 19:45:55

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应该修复的包安装损坏。


还要注意,尽管自制允许多个版本共存,its installation logic isn't quite designed to keep the alternative versions operational,除非它们是通过版本化的公式安装的(例如,常规删除常规brew cleanup中的旧版本)。

因此,如果需要在Python版本之间进行常规切换,或者需要一些为其提供版本化公式的第三方tap,请考虑使用pyenv(也可以通过brew获得)。

相关问题 更多 >