Flask is an open-source web framework built with Python programming language. The software is a light, a fast framework that is minimalistic doesn’t include ORM, form validation and other third party libs. Flash ships with only the essential tools to develop your web applications and maintain them compared to Django, another popular web framework development software. Flask is based on Werkzeug and uses Jinja2 as a template engine.
The installation of Flask can be done in two ways. The first is installing the software from Ubuntu’s official “apt” repository package manager, which is the easiest; however, most people will recommend installing Flask in a virtual environment.
Our guide will go over how to install the software Flask on Ubuntu 20.04 LTS.
Table of Contents
First, make sure your Ubuntu system is up to date. You will need root access or sudo privileges for the install.
sudo apt update && sudo apt upgrade -y
Next, check to see if Python3 is installed.
If Python3 is missing, install it with the following command.
sudo apt install python3
Install PIP For Python3
You will need to install PIP for Python, which enables you to create virtual environments. As stated at the start of our guide, you will install Flask most commonly in a virtual environment.
sudo apt install build-essential python3-pip libffi-dev python3-dev python3-setuptools libssl-dev -y
Install Virtual Environment
Now, you can install the virtual environment that will isolate and run Flask. You do this with the following.
sudo apt install python3-venv
Once the virtual environment is installed, create a flask direct and then open the created directory.
mkdir flask_location && cd flask_location
Create Virtual Environment
In the directory, you now need to run the command to create the virtual environment as follows.
python3 -m venv venv
Now, activate the virtual environment.
You will notice the terminal command line, which now has “venv” to indicate that you are currently working in the virtual environment that has been created.
The final stage now is to install the actual Flask software in your virtual environment. You do this with Pip3, which will install all the components needed for Flask, such as Jinja2, Werkzeug WSG web application library and its modules.
pip3 install flask
Now, confirm the version of Flask to make sure the installation has been completed correctly.
python -m flask --version
The output should be:
Congratulations, you have successfully installed Flask on your Ubuntu 20.04 operating system.
Comments and Conclusion
The guide has shown you how to set up a Python virtual environment and install Flask. For developers needing documentation, the Flask documentation is the best start to visit to learn how to create, deploy your Python applications using Flask.