How to fix ModuleNotFoundError in Nuitka
This workflow guides you through resolving ModuleNotFoundError when running a Nuitka-compiled
binary, specifically caused by missing implicit dependencies (e.g., hidden imports in Cython
modules).
1. Reproduction and Analysis
- Isolate the error: Create a minimal reproduction script (MRE) that triggers the
ModuleNotFoundError. Follow.agents/skills/create-mre/SKILL.mdfor the reduction workflow. - Verify the crash: Run the MRE with Nuitka in standalone mode to confirm the error persists.
- Analyze the traceback:
- Identify the missing module name (e.g.,
pandas._libs._cyutility). - Identify the importer module (e.g.,
pandas._libs.tslibs.ccalendar). - Note: If the importer is a compiled extension (e.g.,
.pyx,.so,.pyd), Nuitka cannot automatically detect imports inside it.
- Identify the missing module name (e.g.,
2. Locate Configuration
- Find the configuration file: Most package-specific configurations are in
nuitka/plugins/standard/standard.nuitka-package.config.yml. - Search for the package: Look for the top-level package (e.g.,
pandas) or the specific submodule in the YAML file.
3. Implement the Fix
Add Implicit Import:
- If the importer module already has an entry, add the missing module to its
implicit-imports->dependslist. - If the importer module is missing, create a new entry for it.
- module-name: 'importer.module.name' implicit-imports: depends: - 'missing.module.name'- If the importer module already has an entry, add the missing module to its
Verify the fix: Re-run the MRE compilation.
- Ensure the
Nuitka-Plugins:implicit-importslog shows the dependency being added (if verbose logging is enabled). - Run the compiled binary and confirm it executes without the
ModuleNotFoundError.
- Ensure the