I have a very simple flask application with 2 files app.py and test.py both under same main folder.
app.py:
from flask import Flask
import subprocess
app = Flask(__name__)
@app.route("/")
def home():
proc = subprocess.Popen(['python', 'test.py'])
return "Hello, Flask!"
test.py:
def main():
print('PING')
if __name__ == '__main__':
main()
I created the virtual environment and added flask into it. When I run app.py using VSCode Python:Flask debugging I got the 'No module named test.py' error like below:
- Serving Flask app 'app.py' (lazy loading)
- Environment: development
- Debug mode: on
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Restarting with stat
- Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them. 127.0.0.1 - - [08/Dec/2021 12:03:46] "GET / HTTP/1.1" 200 - No module named test.py
But when I run it using integrated terminal by 'python -m flask run' everything works fine and 'PING' being printed like below:
- Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them. * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
- Debug mode: off
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 127.0.0.1 - - [08/Dec/2021 12:00:02] "GET / HTTP/1.1" 200 - PING
I guess I miss some python debugging configuration but cannot realize which one. What should I add in order to fix it during debugging?