Back to all fixes
CuratedPython 3.12local
ImportError: attempted relative import with no known parent package
Problem
Running a file that uses `from . import x` directly (e.g. `python pkg/module.py`) fails with 'attempted relative import with no known parent package'.
Solution
python
Relative imports only work when the file is imported as part of a package, not run as a top-level script. Run it as a module from the project root: `python -m pkg.module`. Ensure the package has an `__init__.py` (or is a proper namespace package), or switch to absolute imports (`from pkg import x`).