在DoHlyzer工具中找不到Python模块

2024-10-02 12:30:50 发布

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

我正在尝试使用DoHlyzer tool。当我启动meter文件夹中的dohlyzer.py时,我得到了错误

File "dohlyzer.py", line 8, in <module>  
    from meter.flow_session import generate_session_class  
ModuleNotFoundError: No module named 'meter'

尽管文件夹中有flow_session.py文件


Tags: infrompyimport文件夹session错误line
1条回答
网友
1楼 · 发布于 2024-10-02 12:30:50

问题是该代码没有正确构建,因为它认为自己是作为模块安装的,没有提供适当的setup.py/pyproject.toml文件使其可安装

因此,作为一种快速有效的方法,您可以添加一个示例setup.py文件,以便安装该工具:

#!/usr/bin/env python

from setuptools import setup, find_packages

setup(
    name="dohlyzer",
    description="Set of tools to capture HTTPS traffic, extract statistical and time-series features from it, and analyze them with a focus on detecting and characterizing DoH (DNS-over-HTTPS) traffic.  ",
    long_description=open('README.md').read(),
    long_description_content_type="text/markdown",
    url="https://github.com/ahlashkari/DoHlyzer",
    packages=find_packages(exclude=[]),
    python_requires=">=3.6",
    install_requires=open('requirements.txt').read().split('\n'),
    entry_points={
        "console_scripts": [
            "dohlyzer=meter.dohlyzer:main",
        ]
    },
)

要测试是否可以使用virtualenv,请执行以下操作:

% virtualenv venv
% venv/bin/pip install .
% venv/bin/dohlyzer -h
usage: dohlyzer [-h] (-n INPUT_INTERFACE | -f INPUT_FILE) (-c | -s) output

positional arguments:
  output                output file name (in flow mode) or directory (in sequence mode)

optional arguments:
  -h,  help            show this help message and exit
  -n INPUT_INTERFACE,  online INPUT_INTERFACE,  interface INPUT_INTERFACE
                        capture online data from INPUT_INTERFACE
  -f INPUT_FILE,  offline INPUT_FILE,  file INPUT_FILE
                        capture offline data from INPUT_FILE
  -c,  csv,  flow     output flows as csv
  -s,  json,  sequence
                        output flow segments as json

或者,您可以全局安装它:

% pip install .

注意:setup.py文件有几个问题,只适用于快速破解,如果您想让它变得干净,我建议您阅读some documentation about it

相关问题 更多 >

    热门问题