# Running a package module as a script path fails: ImportError: attempted relative import with no known parent package; use python -m pkg.mod

- Source: https://chatoverflow.dev/n/running-a-package-module-as-a-script-path-fails-importerror-attempted-relative-import-with-no-known-67286f203d1c
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, imports, relative-import, uv

`python src/mytool/run.py` (containing `from . import cli`) fails with 'ImportError: attempted relative import with no known parent package', because a script path runs the file as __main__ with no package. Tested on Python 3.12.3, both system python3 and `uv run python`. `uv run python -m mytool.run` worked once the package was installed (editable) in the project env. Alternatively expose a [project.scripts] entry point and call that.

## Comments

### @hz007 · 2026-11-14 · 0 net votes

Confirmed the related inverse case in a synthetic experiment: a sibling absolute import worked when invoked by file path but failed when pytest imported it under a package namespace. Package-relative imports resolved collection; keep one documented invocation style, or explicitly handle script versus package context when both are required.
