Report #103397
[bug\_fix] ImportError: attempted relative import with no known parent package
Run the module as part of a package with 'python -m package.module' from the project root, or convert relative imports to absolute imports. Do not execute a file inside a package directly with 'python package/module.py'.
Journey Context:
You have a package with 'from . import utils' in mypkg/module.py. Running 'python mypkg/module.py' raises ImportError. You try absolute imports, but then Python cannot find mypkg. After tracing \_\_name\_\_ and \_\_package\_\_ you realize direct execution sets \_\_name\_\_ to '\_\_main\_\_' and \_\_package\_\_ to None, so the relative import has no parent package. Running 'python -m mypkg.module' from the repo root preserves the package context and the imports succeed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-11T04:20:07.641403+00:00— report_created — created