Eventlet-ImportError:没有名为dnskeybase的模块

时间:2019-03-13 23:34:41

标签: python eventlet

我无法在生产系统上导入eventlet。就是说没有名为dnskeybase的模块。

# python scraper.py 
Traceback (most recent call last):
  File "scraper.py", line 7, in <module>
    import eventlet
  File "/usr/lib/python2.7/site-packages/eventlet/__init__.py", line 10, in <module>
    from eventlet import convenience
  File "/usr/lib/python2.7/site-packages/eventlet/convenience.py", line 7, in <module>
    from eventlet.green import socket
  File "/usr/lib/python2.7/site-packages/eventlet/green/socket.py", line 21, in <module>
    from eventlet.support import greendns
  File "/usr/lib/python2.7/site-packages/eventlet/support/greendns.py", line 67, in <module>
    setattr(dns.rdtypes, pkg, import_patched('dns.rdtypes.' + pkg))
  File "/usr/lib/python2.7/site-packages/eventlet/support/greendns.py", line 59, in import_patched
    return patcher.import_patched(module_name, **modules)
  File "/usr/lib/python2.7/site-packages/eventlet/patcher.py", line 120, in import_patched
    *additional_modules + tuple(kw_additional_modules.items()))
  File "/usr/lib/python2.7/site-packages/eventlet/patcher.py", line 94, in inject
    module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
ImportError: No module named dnskeybase

所以我尝试安装它...

# pip install dnskeybase
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting dnskeybase
  Could not find a version that satisfies the requirement dnskeybase (from versions: )
No matching distribution found for dnskeybase

和:

# pip install dnspython
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: dnspython in /usr/lib/python2.7/site-packages (1.16.0)

以及eventlet版本/安装:

# pip install eventlet
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting eventlet
  Using cached https://files.pythonhosted.org/packages/86/7e/96e1412f96eeb2f2eca9342dcc4d5bc9305880a448b603b0a8e54439b71c/eventlet-0.24.1-py2.py3-none-any.whl
Requirement already satisfied: monotonic>=1.4 in /usr/lib/python2.7/site-packages (from eventlet) (1.5)
Requirement already satisfied: six>=1.10.0 in /usr/lib/python2.7/site-packages (from eventlet) (1.12.0)
Requirement already satisfied: dnspython>=1.15.0 in /usr/lib/python2.7/site-packages (from eventlet) (1.16.0)
Requirement already satisfied: greenlet>=0.3 in /usr/lib64/python2.7/site-packages (from eventlet) (0.4.15)
Requirement already satisfied: enum34; python_version < "3.4" in /usr/lib/python2.7/site-packages (from eventlet) (1.1.6)
Installing collected packages: eventlet
Successfully installed eventlet-0.24.1

有什么主意吗?

1 个答案:

答案 0 :(得分:5)

您的本地dnspython软件包安装被破坏,或被位于其他位置的不完整的dns.rdtypes软件包掩盖。 (至少)缺少dns.rdtypes.dnskeybase模块;只是另一个pure-Python module,没什么特别的。

异常消息可能看起来有些混乱,因为它没有命名完整路径。下面的Python表达式在道德上正被执行:

module_name = 'dns.rdtypes.dnskeybase'
__import__(module_name, {}, {}, module_name.split('.')[:-1])

使用__import__ functiondnskeybase包中动态导入dns.rdtypes模块。但是,如果缺少该元素,则引发的ImportError: No module named dnskeybase异常将不包含dns.rdtypes组件,即使这是尝试从中导入的唯一位置。 eventlet.support.greendns模块目前已经导入了dns.rdtypes本身,因此我们知道,对于您的安装来说,该软件包至少存在并且可以导入。

该软件包的常规完整安装会添加一个包含以下文件的site-packages/dns目录(以及相应的.pyc字节缓存文件):

lib/python2.7/site-packages/dns
├── __init__.py
├── _compat.py
├── dnssec.py
├── e164.py
├── edns.py
├── entropy.py
├── exception.py
├── flags.py
├── grange.py
├── hash.py
├── inet.py
├── ipv4.py
├── ipv6.py
├── message.py
├── name.py
├── namedict.py
├── node.py
├── opcode.py
├── py.typed
├── query.py
├── rcode.py
├── rdata.py
├── rdataclass.py
├── rdataset.py
├── rdatatype.py
├── rdtypes
│   ├── ANY
│   │   ├── AFSDB.py
│   │   ├── AVC.py
│   │   ├── CAA.py
│   │   ├── CDNSKEY.py
│   │   ├── CDS.py
│   │   ├── CERT.py
│   │   ├── CNAME.py
│   │   ├── CSYNC.py
│   │   ├── DLV.py
│   │   ├── DNAME.py
│   │   ├── DNSKEY.py
│   │   ├── DS.py
│   │   ├── EUI48.py
│   │   ├── EUI64.py
│   │   ├── GPOS.py
│   │   ├── HINFO.py
│   │   ├── HIP.py
│   │   ├── ISDN.py
│   │   ├── LOC.py
│   │   ├── MX.py
│   │   ├── NS.py
│   │   ├── NSEC.py
│   │   ├── NSEC3.py
│   │   ├── NSEC3PARAM.py
│   │   ├── OPENPGPKEY.py
│   │   ├── PTR.py
│   │   ├── RP.py
│   │   ├── RRSIG.py
│   │   ├── RT.py
│   │   ├── SOA.py
│   │   ├── SPF.py
│   │   ├── SSHFP.py
│   │   ├── TLSA.py
│   │   ├── TXT.py
│   │   ├── URI.py
│   │   ├── X25.py
│   │   └── __init__.py
│   ├── CH
│   │   ├── A.py
│   │   └── __init__.py
│   ├── IN
│   │   ├── A.py
│   │   ├── AAAA.py
│   │   ├── APL.py
│   │   ├── DHCID.py
│   │   ├── IPSECKEY.py
│   │   ├── KX.py
│   │   ├── NAPTR.py
│   │   ├── NSAP.py
│   │   ├── NSAP_PTR.py
│   │   ├── PX.py
│   │   ├── SRV.py
│   │   ├── WKS.py
│   │   └── __init__.py
│   ├── __init__.py
│   ├── dnskeybase.py
│   ├── dsbase.py
│   ├── euibase.py
│   ├── mxbase.py
│   ├── nsbase.py
│   └── txtbase.py
├── renderer.py
├── resolver.py
├── reversename.py
├── rrset.py
├── set.py
├── tokenizer.py
├── tsig.py
├── tsigkeyring.py
├── ttl.py
├── update.py
├── version.py
├── wiredata.py
└── zone.py

正确安装的dnspython版本1.16.0会为文件树中的Python源文件生成以下MD5校验和:

$ ( cd /lib/python2.7/site-packages/dns; export LC_ALL=C; find . -name \*.py -exec md5sum {} \; | sort -k 2 | md5sum )
28e20d8474f4f07287c305dbd5dae8b8  -

如果运行相同的命令并获得不同的输出,则本地安装不完整。

我建议您重新安装该软件包;这是通过pip install --ignore-installed来完成的:

$ pip install --ignore-installed dnspython
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting dnspython
  Using cached https://files.pythonhosted.org/packages/ec/d3/3aa0e7213ef72b8585747aa0e271a9523e713813b9a20177ebe1e939deb0/dnspython-1.16.0-py2.py3-none-any.whl
Installing collected packages: dnspython
Successfully installed dnspython-1.16.0

如果即使重新安装后仍然遇到问题,或者文件树的MD5校验和相同,则python模块搜索路径上有一个 different dns.rdtypes包,即掩盖正确的版本。

您可以通过添加以下内容找到该软件包:

import dns.rdtypes
print(dns.rdtypes.__file__)

scraper.py脚本的顶部,在import eventlet行之前。立即使用import sys; sys.exit(),以防止完全回溯。打印的文件应告诉您在哪里查找有干扰的恶意软件包。找到后,请重命名该dns目录,或调整您的PYTHONPATH环境变量以不包括该dns目录所在的目录,或完全删除它。