I have replicated the scenario in this exact question:
Python error - ImportError: attempted relative import with no known parent package
However, the answer for me does not work. I'm running python3 (3.7.9) in VSCode with the following file structure:
project/
├─ utils/
│ ├─ module.py
├─ server/
│ ├─ main.py
When in the directory all_projects/project/server/:
Running python3 main.py I get ImportError: attempted relative import with no known parent package
Running python3 -m main: ImportError: attempted relative import with no known parent package
-
When in the directory all_projects/project/:
Running python3 -m server.main: ValueError: attempted relative import beyond top-level package
-
ONLY when in the directory all_projects/:
Running python3 -m project.server.main: works as expected.
What the hell is going on here? Why does python3 -m server.main not work in the project directory?