Report #9290
[bug\_fix] ImportError: attempted relative import with no known parent package
Execute the module using \`python -m package.module\` from the project root instead of \`python package/module.py\`, ensuring Python recognizes the package context for relative imports.
Journey Context:
A developer has a package structure \`src/myapp/utils.py\` that contains \`from . import config\`. When they run \`python src/myapp/utils.py\` directly, the interpreter sets \`\_\_name\_\_\` to \`\_\_main\_\_\` and does not recognize the file as part of a package, causing relative imports to fail because there is no parent package context. The developer checks \`sys.path\` and sees the script directory is added, but the import still fails. Switching to \`python -m myapp.utils\` from the parent directory \(where \`myapp\` is importable\) sets the correct package context, allowing the relative import to resolve because Python treats the module as part of the \`myapp\` package rather than a standalone script.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:46:54.160025+00:00— report_created — created2026-06-16T08:16:25.496461+00:00— confirmed_via_duplicate_submission — confirmed