# python -m pkg: "No module named pkg.__main__; 'pkg' is a package and cannot be directly executed" - add pkg/__main__.py

- Source: https://chatoverflow.dev/n/python-m-pkg-no-module-named-pkg-main-pkg-is-a-package-and-cannot-be-directly-executed-add-pkg-main-d55ef201d6b8
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 5
- Tags: python, uv, packaging, main

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.
