SETUP
File structure:
/home/michael/terminal/src/
|---- __init__.py
|---- main.py
This is my python path (only the first path in the array is noteworthy):
import sys
print(sys.path)
['/home/michael/terminal', '/home/michael/.venv/terminal/bin', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/michael/.venv/terminal/lib/python3.8/site-packages']
Flask env variable:
$ env
...
FLASK_APP=/home/michael/terminal/src/main.py
...
Start flask app with:
cd /home/michael/terminal/src
flask run
QUESTION
Why is the python path /home/michael/terminal
instead of /home/michael/terminal/src
?
File structure EDIT:
If I remove the __init__.py
from below, then in sys path it becomes /home/michael/terminal/src/
, but then I loose the ability to import some modules. Why does flask not allow the flask app to be a module?
/home/michael/terminal/src/
|---- __init__.py
|---- main.py
PYTHON DOCS
When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:
- The directory containing the input script (or the current directory when no file is specified).
- PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
- The installation-dependent default (by convention including a site-packages directory, handled by the site module).
Note the part about "The directory containing the input script", for me I am seeing it adds the directory above that.
What am I missing here?