Recently I started working on a new Python project, and I thought I might structure it properly, not throw all the code in one directory like I usually do. Using this tutorial I created a folder structure like this for my project:
myappholder/
myappholder/README.md
myappholder/LICENSE.txt
myappholder/.gitignore
myappholder/myapp/
myappholder/myapp/__init__.py (empty file)
myappholder/myapp/main.py
myappholder/myapp/config.py
myappholder/myapp/subdir
myappholder/myapp/subdir/__init__.py (empty file)
myappholder/myapp/subdir/helper.py
Contents of main.py
:
from myapp.subdir.helper import sayHello
Contents of subdir/helper.py
:
from myapp.config import SOME_CONST
def sayHello():
print(SOME_CONST)
Contents of config.py
:
SOME_CONST = 'Hello world'
When running python main.py
(from myappholder/myapp
), I get this error (trace removed for brevity): ModuleNotFoundError: No module named 'myapp
. When running python -m main
(from myappholder/myapp
) I get the same error.
I know it's probably a really simple thing that I'm doing wrong but a few hours of googling did nothing to fix the problem. I'm not sure if the problem is with how I'm setting up the project or how I'm running it but any help will be appreciated.
Details:
- I'm running Python 3.8 on Windows
- I'm trying to create a GUI application, not a library