启动Jupyter Notebook遇urllib3与OpenSSL版本兼容问题求助
问题:启动Jupyter Notebook时遇urllib3与OpenSSL版本不兼容错误
启动Jupyter Notebook时出现如下错误:
Error loading server extension jupyterlab Traceback (most recent call last): File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/notebook/notebookapp.py", line 2047, in init_server_extensions mod = importlib.import_module(modulename) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/jupyterlab/__init__.py", line 7, in <module> from .handlers.announcements import ( # noqa File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/jupyterlab/handlers/announcements.py", line 15, in <module> from jupyterlab_server.translation_utils import translator File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/jupyterlab_server/__init__.py", line 5, in <module> from .app import LabServerApp File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/jupyterlab_server/app.py", line 14, in <module> from .handlers import LabConfig, add_handlers File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/jupyterlab_server/handlers.py", line 18, in <module> from .listings_handler import ListingsHandler, fetch_listings File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/jupyterlab_server/listings_handler.py", line 8, in <module> import requests File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/Users/kevalshah/myvenv/lib/python3.7/site-packages/urllib3/__init__.py", line 42, in <module> "urllib3 v2.0 only supports OpenSSL 1.1.1+, currently " ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.1.0h 27 Mar 2018'. See: https://github.com/urllib3/urllib3/issues/2168
已尝试安装的版本:
requests==2.31.0urllib3==2.0.7
请问如何解决该问题?是否需要升级系统的OpenSSL?
解决方案
有两种可行方案,优先推荐第一种(无需修改系统环境):
方案1:降级urllib3到兼容版本
urllib3 v2.0+要求OpenSSL 1.1.1+,而当前系统是1.1.0h,直接降级urllib3到支持OpenSSL 1.1.0的版本即可:
- 激活虚拟环境:
source /Users/kevalshah/myvenv/bin/activate - 执行降级命令:
pip install urllib3==1.26.18 - 重新启动Jupyter Notebook:
jupyter notebook
该版本的urllib3兼容OpenSSL 1.1.0,同时能和requests 2.31.0正常配合。
方案2:升级系统OpenSSL并重新编译Python(适合长期使用高版本依赖的场景)
如果确实需要使用urllib3 v2.0+,则需要升级系统OpenSSL并重新编译Python,让Python的ssl模块链接到新的OpenSSL版本:
- 升级系统OpenSSL到1.1.1+(macOS可通过Homebrew安装:
brew install openssl@1.1) - 重新编译Python 3.7,编译时指定链接新安装的OpenSSL:
./configure --with-openssl=$(brew --prefix openssl@1.1) make && make install - 重新创建虚拟环境并安装依赖,再启动Jupyter Notebook
内容的提问来源于stack exchange,提问作者kms
相关产品推荐
相关产品推荐

