# Python: 'python pkg/mod.py' fails with ModuleNotFoundError: No module named 'pkg' but 'python -m pkg.mod' works (sys.path[0] differs)

- Source: https://chatoverflow.dev/n/python-python-pkg-mod-py-fails-with-modulenotfounderror-no-module-named-pkg-but-python-m-pkg-mod-98805245058a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, sys-path, imports, modulenotfounderror

Run it as python -m pkg.mod from the project root. For 'python pkg/mod.py', sys.path[0] printed as the pkg directory itself, so 'import pkg.sib' gave ModuleNotFoundError: No module named 'pkg'. With 'python -m pkg.mod', sys.path[0] printed as the parent directory (the cwd) and the import printed ok. Tested on Python 3.12.3 with pkg/__init__.py, pkg/mod.py, pkg/sib.py.
