【问题标题】:vscode import error: from scapy.all import IPvscode 导入错误:从 scapy.all 导入 IP
【发布时间】:2018-08-15 03:05:39
【问题描述】:

vscode 说在 scapy.all 中找不到 IP

但是从终端,我可以导入它:

谁能告诉我为什么?

【问题讨论】:

  • 确保您在扩展中选择了合适的解释器环境,以便它找到模块。

标签: python visual-studio-code scapy


【解决方案1】:

我在 VS Code 中的 Scapy 代码遇到了完全相同的问题。我认为这与 pylint 的工作方式有关。

当您from scapy.all import IP 时,Python 会加载 scapy/all.py,其中包括 from scapy.layers.all import * 行。 scapy/layers/all.py 包含此代码:

for _l in conf.load_layers:
    log_loading.debug("Loading layer %s" % _l)
    try:
        load_layer(_l, globals_dict=globals(), symb_list=__all__)
    except Exception as e:
        log.warning("can't import layer %s: %s", _l, e)

conf.load_layers 结束于scapy/config.py

load_layers = ['bluetooth', 'bluetooth4LE', 'dhcp', 'dhcp6', 'dns',
               'dot11', 'dot15d4', 'eap', 'gprs', 'hsrp', 'inet',
               'inet6', 'ipsec', 'ir', 'isakmp', 'l2', 'l2tp',
               'llmnr', 'lltd', 'mgcp', 'mobileip', 'netbios',
               'netflow', 'ntp', 'ppp', 'pptp', 'radius', 'rip',
               'rtp', 'sctp', 'sixlowpan', 'skinny', 'smb', 'snmp',
               'tftp', 'vrrp', 'vxlan', 'x509', 'zigbee']

我怀疑 pylint 没有正确遵循这些导入。

我已经尝试了relevant GitHub issue 中建议的解决方法,但它们似乎没有为 Scapy 解决任何问题。 Pylint 最终为 Numpy 中的问题添加了 specific workarounds - 没有人为 Scapy 这样做。

您可以通过直接从 Python 文件顶部的相关层导入 IP 类来解决这些问题:

from scapy.layers.inet import IP, UDP, TCP, ICMP

瞧!没有更多关于这些进口的 pylint 投诉。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-16
    • 2019-11-09
    • 1970-01-01
    • 2018-03-13
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 2020-05-26
    相关资源
    最近更新 更多