Report #41
[bug\_fix] ImportError: attempted relative import with no known parent package
Run the module as part of its package using \`python -m package.module\` from the project root, or convert the relative import to an absolute import after ensuring the package root is on \`sys.path\` \(e.g., via editable install or \`PYTHONPATH\`\).
Journey Context:
You have \`package/module.py\` with \`from . import utils\`. Running \`python package/module.py\` crashes with \`ImportError: attempted relative import with no known parent package\`. Adding \`sys.path\` hacks does not help because Python sets \`\_\_name\_\_ == '\_\_main\_\_'\` and \`\_\_package\_\_\` to \`None\`. Running \`python -m package.module\` sets \`\_\_package\_\_\` correctly and lets Python resolve the parent package, so relative imports work.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:23:13.627983+00:00— report_created — created