How to install Flask on Oracle Linux 9.3
To Install Flask On Oracle Linux 9.3
Introduction:
Flask is a free and open-source microframework for Python that assists developers in constructing secure, scalable, and easily maintainable web applications. It is built on Werkzeug and incorporates Jinja2 as its template engine.
Installation steps:
Step 1: Check the OS version by using the following command
[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.3"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.3"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:3:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.3
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.3
Step 2: Now check the version of the python by using the following command
[root@linuxhelp ~]# python3 --version
Python 3.9.18
Step 3: Check the version of the pip by using the following command
[root@linuxhelp ~]# pip -V
bash: pip: command not found...
Install package 'python3-pip' to provide command 'pip'? [N/y] N
Step 4: If pip is not installed then Install it by using the following command
[root@linuxhelp ~]# dnf install python3-pip -y
Oracle Linux 9 BaseOS Latest (x86_64) 26 kB/s | 3.6 kB 00:00
Oracle Linux 9 BaseOS Latest (x86_64) 17 MB/s | 26 MB 00:01
Oracle Linux 9 Application Stream Packages (x86_64) 25 kB/s | 3.9 kB 00:00
Oracle Linux 9 Application Stream Packages (x86_64) 22 MB/s | 35 MB 00:01
Oracle Linux 9 UEK Release 7 (x86_64) 24 kB/s | 3.0 kB 00:00
Oracle Linux 9 UEK Release 7 (x86_64) 21 MB/s | 34 MB 00:01
Last metadata expiration check: 0:00:08 ago on Tuesday 04 June 2024 12:16:44 AM.
Dependencies resolved.
=====================================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================================
Installing:
python3-pip noarch 21.2.3-8.el9 ol9_appstream 2.9 M
Transaction Summary
=====================================================================================================================================================
Install 1 Package
Total download size: 2.9 M
Installed size: 8.7 M
Downloading Packages:
python3-pip-21.2.3-8.el9.noarch.rpm 10 MB/s | 2.9 MB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------
Total 10 MB/s | 2.9 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : python3-pip-21.2.3-8.el9.noarch 1/1
Running scriptlet: python3-pip-21.2.3-8.el9.noarch 1/1
Verifying : python3-pip-21.2.3-8.el9.noarch 1/1
Installed:
python3-pip-21.2.3-8.el9.noarch
Complete!
Step 5: After the installation, check the pip version again by using the following command
[root@linuxhelp ~]# pip -V
pip 21.2.3 from /usr/lib/python3.9/site-packages/pip (python 3.9)
Step 6: Install the Virtualenv package by using the following command
[root@linuxhelp ~]# dnf install python3
Last metadata expiration check: 0:00:53 ago on Tuesday 04 June 2024 12:16:44 AM.
Package python3-3.9.18-1.el9_3.x86_64 is already installed.
Dependencies resolved.
=====================================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================================
Upgrading:
python-unversioned-command noarch 3.9.18-3.el9 ol9_appstream 8.3 k
python3 x86_64 3.9.18-3.el9 ol9_baseos_latest 30 k
python3-libs x86_64 3.9.18-3.el9 ol9_baseos_latest 9.6 M
Transaction Summary
=====================================================================================================================================================
Upgrade 3 Packages
Total download size: 9.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): python-unversioned-command-3.9.18-3.el9.noarch.rpm 37 kB/s | 8.3 kB 00:00
(2/3): python3-3.9.18-3.el9.x86_64.rpm 127 kB/s | 30 kB 00:00
(3/3): python3-libs-3.9.18-3.el9.x86_64.rpm 15 MB/s | 9.6 MB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------
Total 15 MB/s | 9.7 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Upgrading : python3-libs-3.9.18-3.el9.x86_64 1/6
Upgrading : python-unversioned-command-3.9.18-3.el9.noarch 2/6
Upgrading : python3-3.9.18-3.el9.x86_64 3/6
Cleanup : python3-3.9.18-1.el9_3.x86_64 4/6
Cleanup : python-unversioned-command-3.9.18-1.el9_3.noarch 5/6
Cleanup : python3-libs-3.9.18-1.el9_3.x86_64 6/6
Running scriptlet: python3-libs-3.9.18-1.el9_3.x86_64 6/6
Verifying : python3-3.9.18-3.el9.x86_64 1/6
Verifying : python3-3.9.18-1.el9_3.x86_64 2/6
Verifying : python3-libs-3.9.18-3.el9.x86_64 3/6
Verifying : python3-libs-3.9.18-1.el9_3.x86_64 4/6
Verifying : python-unversioned-command-3.9.18-3.el9.noarch 5/6
Verifying : python-unversioned-command-3.9.18-1.el9_3.noarch 6/6
Upgraded:
python-unversioned-command-3.9.18-3.el9.noarch python3-3.9.18-3.el9.x86_64 python3-libs-3.9.18-3.el9.x86_64
Complete!
Step 7: Create a new python virtual environment by using the following command
[root@linuxhelp ~]# python3 -m venv testenv
Step 8: Once the virtual environment is created, run the following command to activate it.
[root@linuxhelp ~]# source testenv/bin/activate
(testenv) [root@linuxhelp ~]#
Step 9: Now install Flask by using pip install command
(testenv) [root@linuxhelp ~]# pip install flask
Collecting flask
Downloading flask-3.0.3-py3-none-any.whl (101 kB)
|████████████████████████████████| 101 kB 1.1 MB/s
Collecting itsdangerous>=2.1.2
Downloading itsdangerous-2.2.0-py3-none-any.whl (16 kB)
Collecting blinker>=1.6.2
Downloading blinker-1.8.2-py3-none-any.whl (9.5 kB)
Collecting importlib-metadata>=3.6.0
Downloading importlib_metadata-7.1.0-py3-none-any.whl (24 kB)
Collecting Werkzeug>=3.0.0
Downloading werkzeug-3.0.3-py3-none-any.whl (227 kB)
|████████████████████████████████| 227 kB 3.5 MB/s
Collecting click>=8.1.3
Downloading click-8.1.7-py3-none-any.whl (97 kB)
|████████████████████████████████| 97 kB 4.1 MB/s
Collecting Jinja2>=3.1.2
Downloading jinja2-3.1.4-py3-none-any.whl (133 kB)
|████████████████████████████████| 133 kB 6.5 MB/s
Collecting zipp>=0.5
Downloading zipp-3.19.1-py3-none-any.whl (9.0 kB)
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: zipp, MarkupSafe, Werkzeug, Jinja2, itsdangerous, importlib-metadata, click, blinker, flask
Successfully installed Jinja2-3.1.4 MarkupSafe-2.1.5 Werkzeug-3.0.3 blinker-1.8.2 click-8.1.7 flask-3.0.3 importlib-metadata-7.1.0 itsdangerous-2.2.0 zipp-3.19.1
WARNING: You are using pip version 21.2.3; however, version 24.0 is available.
You should consider upgrading via the '/root/testenv/bin/python3 -m pip install --upgrade pip' command.
Step 10: After the installation check the version of the flask by using the following command
(testenv) [root@linuxhelp ~]# flask --version
Python 3.9.18
Flask 3.0.3
Werkzeug 3.0.3
Step 11: Now create a simple Python code file that will import Flash to print a simple Hello message by using the following command.
(testenv) [root@linuxhelp ~]# vim flasktest.py
Add those following Command
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, Flask!'
if __name__ == '__main__':
app.run()
Step 12: Run the file by using the python command.
(testenv) [root@linuxhelp ~]# python3 flasktest.py
* Serving Flask app 'flasktest'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
127.0.0.1 - - [04/Jun/2024 00:20:52] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [04/Jun/2024 00:20:52] "GET /favicon.ico HTTP/1.1" 404 -
Step 13: Now go to the browser and search the following link http:/127.0.0.1:5000
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to install Flask on Oracle Linux 9.3. Your feedback is much welcome.