Python ModuleNotFoundError Debugging Prompt
Debug Python ModuleNotFoundError from the exact traceback, interpreter, environment, import path, project layout, packaging metadata, and launch command.
Prompt Template
You are a senior Python engineer helping me diagnose a ModuleNotFoundError from evidence. Work from the complete traceback, exact interpreter, launch command, working directory, environment, project tree, import statement, package metadata, and deployment context I provide. First distinguish ModuleNotFoundError from ImportError, an exception raised inside an imported module, a circular import, a shadowed standard or third-party module, a missing optional dependency, a packaging or editable-install problem, and an IDE or notebook using a different interpreter. Never invent installed packages, paths, versions, import resolution, shell output, or a successful fix. Do not recommend global or privileged installation by default, deleting environments or lockfiles, weakening package verification, changing `sys.path` blindly, or executing an untrusted setup script. Python implementation and exact version: [details] Operating system, shell, container, notebook, IDE, CI, or deployment runtime: [details] Exact command or action that launches the failing code: [paste] Complete traceback from first line to final exception: [paste sanitized] Failing import and smallest relevant code: [paste] Current working directory and minimal project tree: [paste] Exact interpreter path and environment type: [venv, conda, container, system, other] Package manager, dependency file, lockfile, and relevant package versions: [details] Packaging files and source layout: [pyproject.toml, setup configuration, src layout, namespace packages, other] Read-only environment evidence: [python -c interpreter and path output, package-show output, import-spec check] Local files that may shadow the module or package: [list] Differences between terminal, IDE, notebook, test runner, CI, and production: [details] Recent moves, renames, dependency, environment, or launch-command changes: [details] Security, offline, reproducibility, and deployment constraints: [details] Provide: 1. A concise classification of which module name failed and at what point in the import chain. 2. An evidence table separating confirmed interpreter, environment, working directory, package state, project layout, assumptions, and unknowns. 3. A Python import-resolution trace for the failing name, including parent packages and any shadowing candidates. 4. Safe read-only commands to confirm interpreter identity, environment activation, installed distribution metadata, import specification, current directory, and search path. 5. A ranked root-cause list tied to the supplied evidence rather than a generic instruction to reinstall everything. 6. The smallest reversible fix for the best-supported cause, with exact file or environment scope and why it restores import resolution. 7. Separate remedies when the issue is a missing dependency, wrong interpreter, undeclared dependency, incorrect package layout, bad relative or absolute import, name shadowing, or deployment omission. 8. Verification using the original launch command plus a minimal import check in the same interpreter and environment. 9. Regression protection through dependency declaration, clean-environment installation, CI checks, packaging tests, and documented launch commands where relevant. 10. Rollback steps, remaining unknowns, and the next single piece of evidence to collect if the cause is not proved. Redact tokens, private registry credentials, user paths, internal hostnames, and personal data. Prefer the project's declared environment and package manager, and label every command that would modify dependencies before presenting it.
Example Output
Current Diagnosis
The failing command uses interpreter `[interpreter A]`, while the package evidence was collected from `[interpreter B]`. The traceback therefore supports an environment mismatch; it does not yet prove that the dependency is absent from the intended environment.
Read-Only Checks
1. Run the supplied interpreter directly and print its executable, version, working directory, and search path.
2. With that same interpreter, query the import specification for `[module]`.
3. Ask its package manager for the distribution metadata and compare it with the declared dependency and lockfile.
4. Search the project tree for a local file or directory that shadows `[module]`.
Minimal Fix Shape
Launch the project with the interpreter belonging to `[declared environment]`. If the dependency is truly missing, add it through the project's existing dependency workflow and regenerate only the required lock data.
Verify
Repeat the minimal import and the original command in the same clean environment; do not claim success until both pass.
Tips for Best Results
- ๐กPaste the full traceback and exact launch command; the missing name may be a dependency of the module you imported rather than the top-level package.
- ๐กCollect interpreter and package-manager evidence from the same environment because terminal, IDE, notebook, and CI often point at different Python installations.
- ๐กShow the project tree and packaging files so a missing dependency can be distinguished from a source-layout, relative-import, or name-shadowing problem.
Frequently Asked Questions
What is the Python ModuleNotFoundError Debugging Prompt prompt?
Debug Python ModuleNotFoundError from the exact traceback, interpreter, environment, import path, project layout, packaging metadata, and launch command. It's a free ChatGPT prompt template from our Coding collection โ copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables โ such as [details], [paste], [paste sanitized] โ with your own details before running it. Paste the full traceback and exact launch command; the missing name may be a dependency of the module you imported rather than the top-level package.
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ no signup required.
Related Prompts
Segmentation Fault Debugging Prompt
Debug a segmentation fault from the exact crash signal, source, build flags, backtrace, sanitizer evidence, inputs, and runtime environment.
CORS Error Debugging Prompt
Debug a CORS error from the exact browser message, origins, preflight exchange, server stack, proxy path, credentials mode, and response headers.
CLAUDE.md Generator Prompt
Generate a concise CLAUDE.md repository instruction file from verified project commands, conventions, boundaries, and existing documentation.
GitHub Actions Workflow Generator Prompt
Generate a minimal GitHub Actions workflow from verified repository commands, events, runner needs, permissions, secrets, caching, and deployment constraints.
Docker Command Generator Prompt
Generate a precise Docker CLI command from your goal, environment, current container state, version, and safety constraints.
Google Sheets Formula Generator Prompt
Generate Google Sheets formulas, ARRAYFORMULA expressions, and Apps Script snippets from plain English descriptions.