Search code examples
pythonpython-modulepython-packaging

Python module can't be found in DoHlyzer tool


I'm trying to use the DoHlyzer tool. When I launch dohlyzer.py which is in the meter folder I got the error

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

Although the folder meter have the flow_session.py file.


Solution

  • The issue is that this code is not properly built, as it considers itself being installed as a module, without providing a proper setup.py/pyproject.toml file to make it installable.

    So as a quick'n dirty way to make it work you can add a sample setup.py file so that you can install the tool:

    #!/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",
            ]
        },
    )
    

    To test that you can use a 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
    

    or you can install it globally:

    % pip install .
    

    N.B.: that setup.py file has several issues and is only good for a quick hack, if you want to make it clean, I suggest you to read some documentation about it