For an Ubuntu Python project, Flask needs a place to install its packages without changing Ubuntu’s managed Python. Flask helps a Python app handle web requests and includes commands you can run from a terminal.
In this piece, I’ll walk you through installing Flask in a project environment and checking it with a small application.
TL;DR: Install Flask in a project environment
Create a Python virtual environment in your project, activate it, then install Flask with pip so the package stays separate from Ubuntu’s managed Python.
mkdir my-flask-app
cd my-flask-app
python3 -m venv .venv
source .venv/bin/activate
python -m pip install Flask
python -m flask --version
Use the Python executable inside the environment for package and app commands. If environment creation reports that venv or ensurepip is missing, install Ubuntu’s matching python3-venv package first.
What is Flask and why use a virtual environment?
Flask is a Python web framework that provides request routing and a command-line interface, while leaving many application choices to the developer. The Flask project currently supports Python 3.9 and newer, according to its installation documentation.
A virtual environment is a project-local set of Python packages. It gives the application a place to install its own dependencies.
Ubuntu may mark its system Python as externally managed under PEP 668. This policy helps the operating system maintain its Python packages.
For Python setup beyond this app, see how to install Python on Ubuntu and the Python web development environment guide.
How to install Flask on Ubuntu step by step
Flask’s test client checks the route without opening a network listener, keeping verification focused on the response instead of network configuration.
Step 1: Check Python and create a project folder
Flask’s current documentation requires Python 3.9 or newer. Check the installed Python version, then create a folder where this project’s files and environment will live.
python3 --version
mkdir my-flask-app
cd my-flask-app
The version command returned Python 3.14.7 in my run. Your number can differ, so compare it with the Flask documentation’s supported Python versions.

If python3 is not found or is older than the version Flask supports, use Ubuntu’s supported Python packages or an approved Python installation method before continuing. The command python3 selects the system’s configured Python 3, so confirm its version rather than assuming which minor release it uses.
Step 2: Create and activate a virtual environment
The venv module creates the environment in the project folder. Naming it .venv makes its location clear and keeps it out of the way of the app’s source files.
python3 -m venv .venv
source .venv/bin/activate
After activation, the shell usually adds (.venv) to its prompt and puts the environment’s bin directory first on PATH. Run python -m pip to tie package installation to that interpreter.
If the create command says that ensurepip or venv is unavailable, install the Ubuntu package matching the active Python version, commonly python3-venv, then repeat the command. Package installation changes system files and needs administrator authorization. Check with your administrator before installing packages on a managed machine.
Step 3: Install Flask and check its version
Install Flask from inside the activated environment. Flask’s dependencies, including Werkzeug and Jinja, are installed with it by pip.
python -m pip install Flask
python -m flask --version
Flask 3.1.3 appeared in the version output, and the exact release may change when you install it.

The Flask CLI prints the selected Python and installed Flask version, which helps catch an interpreter mismatch before you run the application.
Step 4: Run a small Flask application
Save the following as flask_smoke_test.py inside the project folder. The route returns a short response that the test client can inspect.
from flask import Flask
app = Flask(__name__)
@app.get("/")
def home():
return "Flask is running"
with app.test_client() as client:
response = client.get("/")
print(f"HTTP {response.status_code}")
print(response.get_data(as_text=True))
Run the exact file with the environment’s interpreter. I ran this command after installing Flask, and it returned HTTP 200 followed by the route’s response text.
.venv/bin/python flask_smoke_test.py
HTTP 200
Flask is running

HTTP 200 is the successful response status, and the next line is the body returned by the route.
When you are ready to explore a Flask device project, see the Flask web server on Raspberry Pi guide. For another Python web stack’s deployment path, the site’s Django, Nginx, Gunicorn and PostgreSQL guide covers a separate application.
Generate trusted SSL certificates for local Flask testing
For local HTTPS testing, use a certificate trusted by your development browser rather than treating Flask’s development server as a public TLS endpoint. A self-signed certificate can encrypt a connection, but browsers will still warn until you explicitly trust its issuer.
Keep certificate files out of source control when they contain private keys. For production, terminate TLS at a maintained reverse proxy or hosting platform. Use its certificate workflow rather than the development server.
| Use | Certificate choice |
|---|---|
| Local browser test | Development certificate trusted by that browser |
| Public deployment | TLS configured at a production proxy or hosting platform |
Uninstall Flask on Ubuntu 24.04
When Flask was installed in this project’s `.venv`, remove the environment to remove Flask and its dependencies together. First deactivate it if it is active, then delete the `.venv` directory from the project folder only after confirming it contains no work you need.
deactivate
rm -r .venv
The removal command is destructive, so verify your current directory and the target name before running it. If Flask was installed in a different environment, activate that environment and use `python -m pip uninstall Flask` instead.
Common Flask installation problems
Common install errors come from a missing venv component or from using pip and Python from different environments.
| Symptom | Likely cause | What to check |
|---|---|---|
| No module named venv or ensurepip | Ubuntu’s venv package is missing for the selected Python | Install the matching python3-venv package through the approved package manager, then recreate .venv |
| externally-managed-environment | pip is targeting Ubuntu’s managed Python | Activate .venv and run python -m pip install Flask |
| flask command not found | Environment is inactive or command is from another interpreter | Activate .venv and use python -m flask --version |
| ImportError when running the app | App is running under a Python without Flask installed | Run .venv/bin/python -m pip show Flask and use .venv/bin/python for the app |
First check whether the environment is active. Then inspect the interpreter path and package metadata to see whether Flask landed in another Python environment.
which python
python -m pip show Flask
python -m flask --version
The first path should point inside .venv/bin, and the package details should list Flask. If they do not, activate the environment again or invoke .venv/bin/python explicitly.
To run the development server from the CLI, identify the module that contains your Flask object. Stop it with Ctrl+C when local testing ends.
A production deployment needs a WSGI server and a separately configured web server or proxy, so keep the built-in server for local checks.
Run `deactivate` when you want the shell to return to its previous Python. The `.venv` directory remains in the project, so later work can activate it again.
Ubuntu 24.04 includes Python tooling through its distribution packages, while Flask is installed into the project environment created above. If the venv command is unavailable, check the package matching the Python interpreter you selected instead of installing Flask into the managed interpreter.
When a route returns a 404, confirm that the requested path matches the route decorator. When the application cannot import Flask, check which Python launches it and whether that interpreter can see the installed package. These checks distinguish a routing issue from an environment issue.
Conclusion: Keep Flask inside the project environment
On Ubuntu, create a project venv, install Flask there, and use its Python to run the application.
For command basics, review how the which command locates executables. Flask’s official installation documentation and quickstart cover the next application steps.
FAQ
These answers cover the install questions that come up when choosing a Python environment on Ubuntu.
How do I install Flask on Ubuntu?
Create and activate a project virtual environment with python3 -m venv .venv and source .venv/bin/activate, then run python -m pip install Flask.
Why should I use a virtual environment for Flask?
A virtual environment keeps Flask and its dependencies separate from Ubuntu’s system Python packages and from other projects.
How can I check that Flask is installed?
With the project environment active, run python -m flask –version. Use the same environment’s Python to run your application.
