Report #74048
[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\`.
Journey Context:
Developer has \`mypkg/\_\_init\_\_.py\` and \`mypkg/module.py\` with \`from . import sibling\`. They run \`python mypkg/module.py\` directly and get ImportError. They try adding \`\_\_package\_\_ = 'mypkg'\` hack at the top of the file, which sometimes works but breaks other imports. They search the docs and realize that when running a file directly as \`\_\_main\_\_\`, Python doesn't treat it as part of a package, so relative imports fail because there's no parent package context. The fix is to run as \`python -m mypkg.module\` from the parent directory, so Python sets up the package context correctly with \`\_\_name\_\_\` as \`mypkg.module\` rather than \`\_\_main\_\_\` without package context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:53:10.179749+00:00— report_created — created2026-06-21T07:08:01.718435+00:00— confirmed_via_duplicate_submission — confirmed