Linux Mint

How to Install Flask on Linux Mint 21

If you are looking to learn working on web applications that are easy to maintain and secure, then go for the Flask Python framework. For that start with using flask which is a free open source and best choice for beginners. Moreover, this python framework is quite easy to install as it doesn’t require any dependencies. So, if you are interested in developing web-based applications using python then install flask on your Linux Mint and for that read this guide.

Installing Flask on Linux Mint 21

The main significance of using Flask is that it comes with built-in Python packages which some extra functionality to this framework, to install it in Linux Mint just go through the steps given below:

Step 1: By default, the Python 3 is installed on almost every Linux distribution but just to be sure let’s check the version of python 3 installed on Linux Mint using:

$ python3 --version

Step 2: Next install the Python virtual environment and pip:

$ sudo apt install python3-venv pip -y

Step 3: Create a directory in which you will save all your work and move to it using change directory command:

$ mkdir Flask && cd Flask

Step 4: Now create flask environment in the created directory and then activate this environment using:

$ python3 -m venv venv && source venv/bin/activate

Step 5: Next, install the Flask framework using pip package manager:

$ pip install Flask

Step 6: Next, check the version of Flask installed to see if it is installed correctly using:

$ python -m flask --version

Using Flask on Linux Mint 21

To demonstrate the use of Flask, let’s create a Python program and run it. Just go through the subsequent steps:

Step 1: First create a Python file in which the code will be written using:

$ nano myflaskapplication.py

Step 2: Now enter the code in the Python file and once you are done with writing the code save the file and then close it:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def my_flask_application():
    return 'Welcome to LinuxHint'

Step 3: Now it’s time to export the application and for that use:

$ export FLASK_APP=myflaskapplication.py


<img class="aligncenter wp-image-265702 size-full" src="https://linuxhint.com/wp-content/uploads/2022/12/install-flask-linux-mint-09.png" alt="" width="936" height="204" />

<strong>Step 4: </strong>After that run the flask application and it will give the IP address along with the port number:

[cc lang="text"  width="100%" height="100%" escaped="true" theme="blackboard" nowrap="0"]
$ flask run

Step 5: Next run the python file by using the IP address along with the port number in your Linux Mint web browser:

127.0.0.1:5000

So, this is how one can install and use the Flask on Linux Mint 21.

If you no longer need this framework then uninstall it using:

$ pip uninstall Flask && deactivate

Conclusion

If you are looking for a Python framework for web application development then Flask is the best Python framework for the users. To install the Flask on a Linux Mint system one needs to install the application using the default package manager.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.