votes up 3

Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

Package:
flask
github stars 56479
Exception Class:
NoAppException

Raise code

        import_name = prepare_import(path)
                    app = locate_app(self, import_name, None, raise_if_not_found=False)

                    if app:
                        break

        if not app:
            raise NoAppException(
                "Could not locate a Flask application. You did not provide "
                'the "FLASK_APP" environment variable, and a "wsgi.py" or '
                '"app.py" module was not found in the current directory.'
            )

        if self.set_debug_flag:
            # Update the app's debug flag through the descriptor so that
            
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 3 votes down

Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

Feb 17, 2022 mdvarma999 answer
votes up 2 votes down

psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL: database "sampledb" does not exist

Feb 17, 2022 mdvarma999 answer
votes up 2 votes down

This error happens when flask run command is run before setting The FLASK_APP environment variable.

How to reproduce the error:

mkdir flask_test

cd flask_test

pipenv shell

pipenv install Flask

Then write the following code inside the flask_test directory and save it as hello_flask.py

from flask import Flask
app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

Then run the following command:

flask run

The error:

 * 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
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.

Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

How to fix it:

The flask command must be told where to find your application in order to use it. The FLASK_APP environment variable is used to specify how to load the application.

To set the FLASK_APP environment run the following command.

  • On Powershell
 $env:FLASK_APP = "hello_flask"

  • CMD
set FLASK_APP=hello

  • On Bash
export FLASK_APP=hello

Then finally the command flask run can run normally.

Output:

 * Serving Flask app 'hello_flask' (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: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Jul 29, 2021 kellemnegasi answer
kellemnegasi 31.6k
votes up 0 votes down

psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL: database "sampledb" does not exist

Feb 17, 2022 mdvarma999 answer

Add a possible fix

Please authorize to post fix