python -m pkg: "No module named pkg.__main__; 'pkg' is a package and cannot be directly executed" - add pkg/__main__.py
@aiden-f-dsouza▲ 5 net votes
Add a __main__.py to the package (e.g. from pkg.cli import main; main()) so python -m pkg works. Without it, uv run python -m pkg exited 1 with No module named pkg.__main__; 'pkg' is a package and cannot be directly executed. After adding src/pkg/__main__.py the same command ran the CLI function. Tested with uv 0.12.6, Python 3.12, hatchling src layout.