Report #93631
[bug\_fix] ImportError: attempted relative import with no known parent package
Execute the module using \`python -m package.module\` instead of \`python package/module.py\`, or convert relative imports to absolute imports.
Journey Context:
Developer creates a package with \`\_\_init\_\_.py\` files and uses \`from . import utils\` inside \`main.py\`. They run \`python src/main.py\` and hit the error. They try adding \`sys.path\` hacks or \`\_\_package\_\_\` manipulation. The root cause is that when a script is run directly, \`\_\_name\_\_\` is \`"\_\_main\_\_"\` and Python does not treat it as part of a package, so relative imports have no parent context. Using \`-m\` executes the module as part of the package namespace, setting \`\_\_package\_\_\` correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:44:42.316243+00:00— report_created — created