How to Install Flask in Ubuntu 20.04 – Python3 and virtual environment

How to install flask on Ubuntu 20.04?

Hi, in this tutorial we are going to see how to set up the flask framework on Ubuntu. But before installing the flask will see the quick intro about flask.


What is flask?

Flask is a micro web framework. It does not have its own database and library dependency like the Django. For the newbie it is the good to start with flask framework.

Now We see How to setup the flask on Ubuntu machine using python.  There are two ways to setup flask on the Ubuntu20.04 machine

  1. Direct installation using the pip
  2. Installation using the virtual environment

Direct installation using pip

Then benefit for ubuntu20.04 is, It come with preinstall python3.6 version so you need not struggle for setup python unlike the previous version

Step 1: First update your Ubuntu system using the following command

sudo apt update -y

2: Install flask using pip command

pip3 install flask



Step 3: To verify flask is installed use the following command

flask --version

Installation using the virtual environment

 In second method we are going to see installation of flask using virtual environment.

Step 1: First create a folder and enter to the folder using the following command

mkdir Project && cd Project

Command explanation:
mkdir – mkdir means make directory/folder
cd – cd means change directory/folder

In the above command we are executing two commands at a time the first command is creating directory/folder by name Project and then entering that directory/folder.

Once we enter to this directory now we are ready to install virtual environment.

What is virtual environment?

Virtual environment is nothing but a wrapper/folder which holds all your libraries and project dependency related to your project.

Step 2: create a virtual environment using python3 command

python3 -m venv projectven

Command explanation:
python3: we are creating virtual environment for python3
-m:  -m means make
Venv: venv stand for virtual environment
Projectven: is the name of your virtual environment.

Now you need to install python3-venv to create a virtual environment using the following command.

sudo apt-get install python3-venv

Now execute the following command

python3 -m venv projectven

Step 3: Now you need to activate your virtual environment using following command

source projectven/bin/activate

once your virtual environment is activated it will show you (projectven) at the beginning of your command

Step 4: Now you are ready to install flask in virtual environment. Use the following command

pip3 install flask

Step 5: To confirm that flask is installed, run:

flask --version

Thanks for reading !!! if you face any issue ask in a comment

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x