firmware-mod-kit
firmware-mod-kit copied to clipboard
Fix: "ModuleNotFoundError: No module named 'imp'" on python 3.12
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