In this article we will show you how to install Flask on CentOS 8 operating system.
Introduction
Flask is a popular Python web framework that provides a simple and easy-to-use interface for building web applications. It is designed to be lightweight and modular, making it easy to add new features and functionality as needed.
Here are some of the key features and characteristics of Flask:
- Micro framework: Flask is a “micro” framework, which means that it provides only the basic functionality needed to build web applications. This makes it lightweight and easy to use, but also means that it may not be suitable for very complex or large-scale applications.
- Routing: Flask provides a simple routing system that maps URLs to specific Python functions, making it easy to create dynamic web pages.
Templating: Flask includes a built-in templating engine that allows developers to create dynamic HTML pages with placeholders for dynamic content. - Flask extensions: Flask has a wide range of third-party extensions that can be used to add additional functionality to the framework, such as support for database integration, user authentication, and more.
- RESTful support: Flask includes built-in support for creating RESTful APIs, making it easy to build web services that can be used by other applications.
- Jinja2 template engine: Flask uses the Jinja2 template engine, which is a powerful and flexible templating language that allows developers to create dynamic HTML pages with ease.
Flask Installation On CentOS 8
Prerequisites
Before we proceed to the Flask installation process, there are several prerequisites that must be met, namely :
- A server running one of the following operating systems: CentOS 8.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A root user access or normal user with administrative privileges.
The Flask installation will be consiste of several steps, as mentioned below :
- Update CentOS 8 System
- Creating Virtual Environment
- Installing Flask
- Verifying Flask
1. Update CentOS 8 System
The first is to update our CentOS 8 system, this task is to make sure if we are accessing the latest packages versions. This task will cut down the installation time. To update our packages software we will use command line :
$ sudo dnf update -y
2. Creating Virtual Environment
In this step, we will create Python3 virtual environment where Flask will be lived in. For this purpose we will submit the following command line :
# python3 --version
# mkdir projekgue # cd projekgue/ # python3 -m venv venv # . venv/bin/activate
The output will be as shown below :
[root@otodiginet ~]# python3 --version Python 3.6.8 [root@otodiginet ~]# mkdir projekgue [root@otodiginet ~]# cd projekgue/ [root@otodiginet projekgue]# python3 -m venv venv [root@otodiginet projekgue]# . venv/bin/activate
3. Installing Flask
Within the activated environment, we will use the following command to install Flask :
(venv) [root@otodiginet projekgue]# pip install Flask
Output :
(venv) [root@otodiginet projekgue]# pip install Flask Collecting Flask Downloading https://files.pythonhosted.org/packages/f2/28/2a03252dfb9ebf377f40fba6a7841b47083260bf8bd8e737b0c6952df83f/Flask-1.1.2-py2.py3-none-any.whl (94kB) 100% |████████████████████████████████| 102kB 1.2MB/s Collecting Jinja2>=2.10.1 (from Flask) Downloading https://files.pythonhosted.org/packages/7e/c2/1eece8c95ddbc9b1aeb64f5783a9e07a286de42191b7204d67b7496ddf35/Jinja2-2.11.3-py2.py3-none-any.whl (125kB) 100% |████████████████████████████████| 133kB 1.4MB/s Collecting Werkzeug>=0.15 (from Flask) Downloading https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl (298kB) 100% |████████████████████████████████| 307kB 625kB/s Collecting itsdangerous>=0.24 (from Flask) Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl Collecting click>=5.1 (from Flask) Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB) 100% |████████████████████████████████| 92kB 1.1MB/s Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->Flask) Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl Installing collected packages: MarkupSafe, Jinja2, Werkzeug, itsdangerous, click, Flask Successfully installed Flask-1.1.2 Jinja2-2.11.3 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 itsdangerous-1.1.0 You are using pip version 9.0.3, however version 21.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
3.1. Upgrading pip
At this point, we have successfully installed Flask, according to the recommendations above, we will upgrade pip to version 21 using the command line.
(venv) [root@otodiginet projekgue]# pip install --upgrade pip
Output :
(venv) [root@otodiginet projekgue]# pip install --upgrade pip Collecting pip Downloading https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl (1.5MB) 100% |████████████████████████████████| 1.5MB 320kB/s Installing collected packages: pip Found existing installation: pip 9.0.3 Uninstalling pip-9.0.3: Successfully uninstalled pip-9.0.3 Successfully installed pip-21.0.1
4. Verifty Flask Installation
At this step, we will verify the installation with the following command which will print the Flask version:
(venv) [root@otodiginet projekgue]# python -m flask --version
Output :
(venv) [root@otodiginet projekgue]# python -m flask --version Python 3.6.8 Flask 1.1.2 Werkzeug 1.0.1
Conclusion
In this tutorial we have learned how to install Flask on CentOS 8. I hope this tutorial will be helpful.