Labs ICT
โญ Pro Login

Setting Up Flask

Installing Flask and running your first app.

Setting Up Flask

Getting Flask running on your machine takes just a few commands. Start by installing it with pip:

pip install flask

Verify the installation worked by importing it in a Python shell:

python -c "import flask; print(flask.__version__)"

Next, create a file called app.py โ€” this will be your application's entry point. Inside it, import Flask and create an instance:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, Flask!"

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

Run the app with python app.py. Alternatively, Flask provides a CLI command: just set the FLASK_APP environment variable and run flask run:

# Windows
set FLASK_APP=app.py
flask run

For development, enable debug mode so changes auto-reload and you get detailed error pages:

set FLASK_DEBUG=1
flask run

One last thing โ€” always work inside a virtual environment. It keeps your project dependencies isolated from the rest of your system:

python -m venv venv
venv\Scripts\activate   # Windows
pip install flask

With that setup, you're ready to start building.

๐Ÿงช Quick Quiz

How do you install Flask?