Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions
In this tutorial, i am going to show you how to create a Python virtual environment and install Flask on Ubuntu 22.04 system.
How to Install Python Flask on Ubuntu 22.04 using Terminal
Use the below given steps and how to create a Python virtual environment and install Flask on your Ubuntu 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
Now, run the following command on terminal to update Apt package list:
sudo apt-get update
Step 3 – Verify Python Installed In Your System
Run the following command to verify that Python is installed on your ubuntu 22.04 system:
python3 -V
Output will be:
Python 3.9.0
Step 4 – Installing Flask
Run 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 run the following command to create directory, which name flask_app:
mkdir flask_app && cd flask_app
Then run 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
Run the following command to activate the activate
script:
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
In this tutorial, i have shown to you 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.
Be First to Comment