TL;DR
ImportError: attempted relative import with no known parent package means Python ran your file as a script, so it has no package to resolve from .x import y against.
The fix: cd to the directory that contains your package and run python -m myapp.cli , not python myapp/cli.py . With a src/ layout, pip install -e . once and -m works from anywhere.
Python decides from the module's package, __spec__.parent (and the older __package__ ). Run as a file both are None , and run with -m the package is 'myapp' . Adding __init__.py does not change that.
Big projects differ. Airflow bans relative imports with a lint rule (0 in 6,813 files across core, task SDK and providers). Django mixes them, with 2,991 absolute and 256 relative import lines in its package.
The repros below are real runs on Python 3.13.5 and pytest 9.2.0.…