Python Flask complains of a "No module named demo" error when running from VSCode

27 views Asked by At

I have a super simple flask application:

from flask import Flask

app = Flask("__name__")


@app.route("/")
def index():
    return "random, World!"


if __name__ == "__main__":
    app.run(debug=True)

This is in a file called demo.py in a large VSCode Repository

For some reason, when I try and run this code, I get this command line behaviour:

 * Serving Flask app '__name__' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
 * Restarting with watchdog (windowsapi)
No module named demo

Whereas when I run the same program via navigating to it in command prompt, and just using python demo.py it runs fine.

Note my python version is 10.5

Any help at all would be appreciated, demo.py is in a repository opened up in vscode and I am pretty sure that is why this is happening. But I don't know how to resolve it.

0

There are 0 answers