How to Install python flask in ubuntu system using terminal. In this tutorial, you will learn how to create a Python virtual environment and install Flask on your Ubuntu 20.04/22.04 machine.
This tutorial guide will help you step by step on how to install Flask on Ubuntu 20.04/22.04 inside a Python virtual environment.
How to Install Python Flask on Ubuntu 20.04/22.04 using Terminal
Follow the following steps and how to create a Python virtual environment and install Flask on your Ubuntu 20.04/22.04 machine:
Step 1 – Open Terminal OR Command Prompt
First of all, your terminal or command prompt by pressing Ctrl+Alt+T key:
Step 2 – Update APT Package
In this step, visit your terminal and execute the following command to update Apt package list:
sudo apt-get update
Step 3 – Verify Python Installed In Your System
In this step, You need to verify that Python is installed on your ubuntu 20.04/22.04 system by executing the following command on terminal:
python3 -V
Output will be:
Python 3.9.0
Step 4 – Installing Flask
In this step, execute the following commands on your terminal to install flask.
The recommended way to create a virtual environment is by using the venv
module, which is provided by the python3-venv
package. So, execute the following command to install the package:
sudo apt install python3-venv
After that, Create a new directory for the Flask application and switch into it. So open your terminal and execute the following command to create directory, which name flask_app:
mkdir flask_app && cd flask_app
Then execute the following command inside the directory to create the virtual environment:
python3 -m venv venv
The command will create a directory called venv
, which contains a copy of the Python binary, the Pip package manager , the standard Python library, and other supporting files. You can use any name you want for the virtual environment.
Step 4 – Activate Script
In this step, you need to activate the activate
script. So open your terminal and execute the following command on it:
source venv/bin/activate
Once activated, the virtual environment’s bin directory will be added at the beginning of the $PATH
variable. Your shell’s prompt will also change and show the name of the virtual environment you’re currently using. In this example that is venv
.
Now that the virtual environment is activated, use the Python package manager pip
to install Flask:
pip install Flask
To verify the installation, run the following command, which prints the Flask version:
python -m flask --version
Conclusion
How to install flask on ubuntu 20.04/22.04. In this tutorial, you have learned how to create a Python virtual environment and install Flask on your Ubuntu 20.04/22.04 machine.
That’s it. Python Flask has been download on your Ubuntu system.
Recommended Ubuntu Posts