Report #100969
[bug\_fix] ImportError: attempted relative import with no known parent package when running a module inside a package directly
Run the package as a module with python -m package.module instead of python package/module.py, or use an absolute import if the package is installed.
Journey Context:
You have package/submodule.py containing from . import sibling. You run python package/submodule.py directly and it crashes with ImportError: attempted relative import with no known parent package. You check the import and it looks correct. The problem is that executing a file directly sets \_\_name\_\_ to '\_\_main\_\_' and \_\_package\_\_ to None, so Python treats the file as a standalone script, not as part of package. The fix is to run it as python -m package.submodule from the project root, which preserves package context and makes the relative import resolve.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:45:38.285389+00:00— report_created — created