Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: "ModuleNotFoundError: No module named 'imp'" on python 3.12 #191

Open
vietanhtwdk opened this issue Sep 1, 2024 · 0 comments
Open

Comments

@vietanhtwdk
Copy link

Issue

When extract image on ubuntu with python 3.12 will have error

    import binwalk
  File "/workspace/firmware-mod-kit/src/binwalk-2.1.1/src/binwalk/__init__.py", line 3, in <module>
    from binwalk.core.module import Modules, ModuleException
  File "/workspace/firmware-mod-kit/src/binwalk-2.1.1/src/binwalk/core/module.py", line 16, in <module>
    import binwalk.core.plugin
  File "/workspace/firmware-mod-kit/src/binwalk-2.1.1/src/binwalk/core/plugin.py", line 5, in <module>
    import imp
ModuleNotFoundError: No module named 'imp'

This because imp module has been removed.
https://stackoverflow.com/questions/76694726/replacing-imp-load-source-in-python-3-12
https://docs.python.org/3/whatsnew/3.12.html#imp

Temp fix

Edit this file firmware-mod-kit/src/binwalk-2.1.1/src/binwalk/core/plugin.py

  • Remove import imp
  • Add this to top of file
import importlib.util
import importlib.machinery

def load_source(modname, filename):
    loader = importlib.machinery.SourceFileLoader(modname, filename)
    spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
    module = importlib.util.module_from_spec(spec)
    # The module is always executed and not cached in sys.modules.
    # Uncomment the following line to cache the module.
    # sys.modules[module.__name__] = module
    loader.exec_module(module)
    return module
  • Replace imp.load_source with load_source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant