python venv flask

  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:

  2. On Windows:

bash venv\Scripts\activate

  • On macOS and Linux:

bash source venv/bin/activate

  1. Install Flask within the virtual environment:
pip install Flask
  1. Create a Flask application file, e.g.,

  2. Open the file and define a Flask application:

from flask import Flask

app = Flask(__name__)

def hello():
    return 'Hello, World!'

if __name__ == '__main__':
  1. Save the file.

  2. Run the Flask application:

  1. Open a web browser and go to to see the "Hello, World!" message.

  2. To stop the Flask application, press Ctrl+C in the terminal where it's running.

  3. Deactivate the virtual environment: