Skip to content

Flask - Environment

Flask – Setting Up Your Development Environment

Section titled “Flask – Setting Up Your Development Environment”

Flask requires Python 3.8 or newer. While Flask itself and its core dependencies (Werkzeug, Jinja2, ItsDangerous, Click) work well on modern Python versions, it’s always good practice to check the compatibility of any Flask extensions you plan to use.

It is highly recommended to use a virtual environment for any Python project, including Flask applications. Virtual environments create isolated Python setups, preventing conflicts between dependencies of different projects. Python 3 includes the built-in venv module for this purpose.

To create a virtual environment, navigate to your project directory in the terminal and run:

# Replace 'venv' with your preferred environment name
python -m venv venv

This command creates a venv folder containing a copy of the Python interpreter and a place to install project-specific libraries.

To activate the virtual environment:

source venv/bin/activate
venv\Scripts\activate.bat
venv\Scripts\Activate.ps1

Note: You might need to adjust your system’s execution policy to run PowerShell scripts. You’ll know the environment is active when your terminal prompt is prefixed with (venv).

With your virtual environment activated, you can install Flask using pip, the Python package installer:

pip install Flask

This command downloads and installs Flask and its essential dependencies:

  • Werkzeug: Implements WSGI, the standard interface between Python web applications and servers.
  • Jinja2: A powerful and flexible templating engine.
  • ItsDangerous: Securely signs data to ensure its integrity.
  • Click: A framework for creating command-line interfaces (used for the flask command).
  • MarkupSafe: Escapes characters so text is safe to render in HTML.

You should see output indicating the successful installation of these packages. The specific versions will depend on the latest releases available.

While you can install Flask system-wide (outside a virtual environment), it’s strongly discouraged as it can lead to dependency conflicts between different projects on your system.