首页 > 解决方案 > 导入 eventlet SSL 导致:ModuleNotFoundError: No module named 'OpenSSL.tsafe'

问题描述

为什么在尝试导入 eventlet 的 SSL 模块时出现以下导入错误:

ModuleNotFoundError: No module named 'OpenSSL.tsafe'

eventlet 的 OpenSSL 是否与最新版本的 pyOpenSSL 不兼容?

复制步骤

使用以下 Pipenv:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"

[packages]
pyOpenSSL = "*"
eventlet = "*"

[requires]
python_version = "3"

使用该文件创建一个 pipenv:

$ pipenv install
Creating a virtualenv for this project…
Pipfile: /tmp/Pipfile
Using /usr/local/bin/python3.8 (3.8.3) to create virtualenv…
...
Successfully created virtual environment! 
...

现在导入 eventlet.green.OpenSSL.SSL:

$ pipenv run python
Python 3.8.3 (default, Jun 29 2020, 18:02:49) 
[GCC 8.3.1 20190311 (Red Hat 8.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from eventlet.green.OpenSSL import SSL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/myuser/.local/share/virtualenvs/tmp-XVr6zr33/lib/python3.8/site-packages/eventlet/green/OpenSSL/__init__.py", line 3, in <module>
    from . import tsafe
  File "/home/myuser/.local/share/virtualenvs/tmp-XVr6zr33/lib/python3.8/site-packages/eventlet/green/OpenSSL/tsafe.py", line 1, in <module>
    from OpenSSL.tsafe import *
ModuleNotFoundError: No module named 'OpenSSL.tsafe'
>>> 

标签: python-3.xpyopenssleventlet

解决方案


经过一段时间的挖掘,看起来 eventlet 目前确实不适用于截至本文发布时四天前发布的最新 20.0.0 PyOpenSSL 包。我向 eventlet 提出了一个问题:

https://github.com/eventlet/eventlet/issues/671

在更新 eventlet 之前,我们必须将 PyOpenSSL 固定到以前的 19.1.0 版本(根据问题中的 Pipfile):

pyOpenSSL = "==19.1.0"

推荐阅读