Python is a popular, powerful programming language that is easy to get started and understand. It is general-purpose Language with high-level data structures like flexible arrays and dictionaries and a simple but effective approach to object-oriented programming. It is an ideal language for scripting and rapid application development in many areas on most platforms due to its elegant syntax and dynamic typing, together with its interpreted nature.
Python allows you to split your program into modules that are reusable by other Programs. It is a high-level language meaning it uses the natural language elements for automation thus offering more error checking than low-level languages that include C programming Language. Python is an interpreted language which makes it easier to use for development as it requires no compiling.
Python is Cross-platform and available on Windows, Linux, and macOS Operating Systems. It is Open-Source making it free to be usable and distributable, for personal and commercial use.
The latest version 3.10 has new and improved features that include;
- Parenthesized context managers – Supports using enclosing parentheses for continuation across multiple lines in context managers.
- Better Error Messages – An error with unclosed parenthesis contains the location of the syntax error.
- Precise line numbers for debugging and other tools.
- Structural Pattern Matching in the form of match statements and case statements of patterns.
- A new type of union operator that enables the syntax X | Y which expresses ‘either type X or type Y‘
- Introduced new modules including; asyncio, agpass, array, base64, etc.
This guide will show you how to Install Python 3.10 on CentOS 9 / AlmaLinux 9
Install Python 3.10 on CentOS 9 / AlmaLinux 9 / RHEL 9
Update your system packages.
sudo dnf update -y
Install dependencies for the package.
sudo yum install zlib-devel bzip2-devel gcc libffi-devel make -y
Download Python3.10 from the source. Alternatively, you could use the wget utility.
Unzip the file with the following command.
tar -xvf Python-3.10.6.tar.xz
Change to the decompressed directory to compile the source code.
cd Python-3.10.6 ./configure --enable-optimizations make
This may take some time depending on your processor and internet speed. Then run the installation with the following command.
sudo make install
To verify installation, check the version
$ python3 --version Python 3.10.6
Installing Python Modules
To install Python Modules, we can do so with the recommended method of using a pip installer. With Python 3.4 and above pip is already installed by default. You can confirm this by checking the version.
$ pip3 --version pip 22.0.4 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
Ensure that the copies of setuptools and wheel projects are up to date to ensure you can also install from source archives:
$ python -m pip install --upgrade pip setuptools wheel Requirement already satisfied: pip in /usr/local/lib/python3.10/site-packages (22.0.4) Requirement already satisfied: setuptools in /usr/local/lib/python3.10/site-packages (58.1.0) Requirement already satisfied: wheel in /usr/local/lib/python3.10/site-packages (0.37.1)
To search for a package, use the following command syntax. Replacing the query term with the name of the package.
python -m pip search "query"
To install a module, we use the following syntax
python -m pip install PackageName
If for example, I want to install Flask, I would use the following command
$ python -m pip install flask .... Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.1 Werkzeug-2.2.1 click-8.1.3 flask-2.1.3 importlib-metadata-4.12.0 itsdangerous-2.1.2 zipp-3.8.1
You can check for the version of the module by using the following command.
python -m pip show PackageName
So for the Flask module, I will use the following command:
$ python -m pip show flask Name: Flask Version: 2.1.3 Summary: A simple framework for building complex web applications. Home-page: https://palletsprojects.com/p/flask Author: Armin Ronacher Author-email: [email protected] License: BSD-3-Clause Location: /home/technixleo/usr/local/lib/python3.10/site-packages Requires: Werkzeug, Jinja2, itsdangerous, importlib-metadata, click Required-by:
You can upgrade a module explicitly by using the following command
python -m pip install --upgrade SomePackage
To upgrade the module I have installed, I would use
$ python -m pip install --upgrade flask Requirement already satisfied: flask in ./usr/local/lib/python3.10/site-packages(2.1.3) Requirement already satisfied: click>=8.0 in ./usr/local/lib/python3.10/site-packages (from flask) (8.1.3) Requirement already satisfied: Jinja2>=3.0 in ./usr/local/lib/python3.10/site-packages (from flask) (3.1.2) Requirement already satisfied: itsdangerous>=2.0 in ./usr/local/lib/python3.10/site-packages (from flask) (2.1.2) Requirement already satisfied: Werkzeug>=2.0 in ./usr/local/lib/python3.10/site-packages (from flask) (2.2.1) Requirement already satisfied: importlib-metadata>=3.6.0 in ./usr/local/lib/python3.10/site-packages (from flask) (4.12.0) Requirement already satisfied: zipp>=0.5 in ./usr/local/lib/python3.10/site-packages (from importlib-metadata>=3.6.0->flask) (3.8.1) Requirement already satisfied: MarkupSafe>=2.0 in ./usr/local/lib/python3.10/site-packages (from Jinja2>=3.0->flask) (2.1.1)
To install Python packages that are isolated to a specific user, use the following command syntax
python -m pip install --user PackageName
Replacing the user and SomeProject with the actual names of the package. For example, to install a package for the current user on the system, I would use the following command.
$ python -m pip install --user pandas Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/site-packages (from python-dateutil>=2.8.1->pandas) (1.15.0) Installing collected packages: pytz, numpy, pandas Successfully installed numpy-1.23.1 pandas-1.4.3 pytz-2022.1
To list Packages installed
python -m pip list
To uninstall a package, use the following command syntax.
python -m pip uninstall PackageName
If I want to unintall Pandas, I would use the follwoing comamnd.
Found existing installation: pandas 1.4.3 Uninstalling pandas-1.4.3: Would remove: /home/technixleo/usr/local/lib/python3.10/site-packages/pandas-1.4.3.dist-info/* /home/technixleo/usr/local/lib/python3.10/site-packages/pandas/* Proceed (Y/n)? y Successfully uninstalled pandas-1.4.3
Sample Python Program on CentOS 9|AlmaLinux 9|RHEL 9
Let us create a simple program name “hello world”.
Invoke the Python Interpreter with the following command
$ python3.10 Python 3.10.5 (main, Jul 30 2022, 01:19:32) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
Enter the following code then press Enter which gives an output of the statement.
>>> print("Hello, My fellow Pythonistas!") Hello, My fellow Pythonistas!
You can also pay around with the statements
>>> print("Hello,\nMy fellow Pythonistas!") Hello, My fellow Pythonistas!
You can also use Python as a calculator. Try running the following expressions to get a value.
>>> 3+8 11 >>> 2*7 14 >>> 60/5 12.0
This guide has shown you how to Install Python 3.10 on CentOS 9 / AlmaLinux 9. Python is a popular Programming that is easy to learn and get started as we have seen. It is a general-purpose programming language that can be used in Machine Learning and the development of web and desktop applications.