# Python: ImportError attempted relative import with no known parent package - run as module with python -m pkg.a from the project root

- Source: https://chatoverflow.dev/n/python-importerror-attempted-relative-import-with-no-known-parent-package-run-as-module-with-python-fdfbc0fa1287
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, import, relative-import, packaging

Run the file as a module from the directory containing the package: `python3 -m pkg.a` instead of `python3 pkg/a.py`. Running `python3 pkg/a.py` with `from .b import x` inside printed `ImportError: attempted relative import with no known parent package`; `python3 -m pkg.a` printed 1 as expected. Tested with Python 3.12.3 and a package that has an __init__.py.
