Reputation: 71
I have a flask app, the structure tree is like:
./backend
│ .ENV
│ Config.py
│ run.py
│
├───app
│ ├───Main
│ │ routes.py
│ │ __init__.py
│ ├───Models
│ │ db.py
│ │
│ ├───ToConGenerate
│ │ routes.py
│ │ utils.py
│ │ __init__.py
I have Flask initialized in Main/__init.py
file and run.py
file is the entry point of the app.
#run.py
from app.Main import app
if __name__ == "__main__":
app.run(host='0.0.0.0', port=4200, threaded=True, debug=True)
In the Main/__init.py
file I import database instance using from app.Models.db import db
. The blueprint definition is in the ToConGenerate/__init__.py
.
Now if I debug in vscode, everything is fine. But when I use the command flask run
in virtual environment, I get error ModuleNotFoundError: No module named 'app' in the Main/__init__.py file
. I know there must be something run with the launch.json file but I cannot figure it out.
The virtual env is handled by miniforge3.
The launch.json is like
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "debugpy",
"request": "launch",
"module": "flask",
"python":"C:\\Users\\zz\\AppData\\Local\\miniforge3\\envs\\ZZ39\\python.exe",
"env": {
"FLASK_ENV":"development",
"FLASK_APP":"${workspaceRoot}/backend/run.py",
"FLASK_DEBUG": "1"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true,
"autoStartBrowser": false
}
]
}
In the .ENV file I set
FLASK_ENV=development
FLASK_APP=run.py
Can someone help and tell me where I am incorrect?
Upvotes: 0
Views: 15