Python is one of the most popular high-level languages, focusing on high-level and object-oriented applications from simple scrips to complex machine learning algorithms. Python 3.10 is the latest release and is not classed as stable compared the Python 3.9, but the final candidate is expected to be completed on the 4th of October 2021.
Some of the features Python can do:
- Python can be used on a server to create web applications.
- Python can be used alongside software to create workflows.
- Python can connect to database systems. It can also read and modify files.
- Python can be used to handle big data and perform complex mathematics.
- Python can be used for rapid prototyping or production-ready software development.
For users and especially developers wanting to try out Python’s latest release, you will know how to install Python 3.10 on Almalinux 8.
Table of Contents
- Recommended OS: AlmaLinux 8.
- User account: A user account with sudo privilages or root access (su command).
Updating Operating System
Update your AlmaLinux operating system to make sure all existing packages are up to date:
sudo dnf update && sudo dnf upgrade -y
The tutorial will be using the sudo command and assuming you have sudo status. To verify sudo status on your account:
Example output showing sudo status:
[[email protected] ~]$ sudo whoami root
If you have not set up a sudo user account and would like to, visit our tutorial on How to Add a User to Sudoers on AlmaLinux.
To use the root account, use the following command with the root password to log in.
Install Python 3.10 Manually
The first option is to install Python 3.10 from the source. This is a straightforward process, even with compiling from the source. First, you will need to install the dependencies necessary to build Python 3.10:
sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y
The second part is visiting the downloads page on Python’s website and getting the latest version using (wget):
Note, this is Python 3.10 stable version; visit and check for updates.
The file archive is small, so it won’t take a long time to download. Once done, extract the archive:
tar -xf Python-3.10.0.tar.xz
You will need to switch to the source directory and run the configuration script, which does an essential run-through checklist to ensure all dependencies are present for the installation to work.
cd Python-3.10.0 && ./configure --enable-optimizations
Note, the (–enabled-optimizations) is recommended as it optimizes the Python binary by running multiple tests but takes extra time to compete. Overall the process should take a few minutes, so it’s recommended not to skip.
Example end output:
The next option is to use the (make) command to start the build process.
make -j 2
Note, the (-j) corresponds to the number of cores in your system to speed up the build time. If you have a powerful server, you can set this as high as you like. If you don’t, then it will be the default option of 1. To find out how many cores you have on your system, execute the following code:
Example output of cores LinuxCapable test operating system has:
As you can see, we have 2 cores, so in the (make) command, so (-j 2) was used to utilize the two cores.
In the last step, once you have finished with the build process, you will install Python 3.10 source by executing the following:
sudo make altinstall
Note, the guide has used (altinstall) instead of the default (install) because it will overwrite the default python3 binary python binary file /usr/bin/python.
Check the version of the installation to make sure it has been installed successfully and its current build number:
Create a Test Virtual Environment
Python’s venv module is a virtual environment is a Python environment such that the Python interpreter, libraries, and scripts installed into it are isolated from those established in other virtual environments, and (by default) any libraries installed on your operating system, for example, those that are installed on your AlmaLinux operating system to avoid clashing and disturbing your production environments.
To make sure Python 3.10 is installed correctly and functioning, create a quick Python project as follows.
First, create the project directory and navigate to it:
mkdir ~/test_app && cd ~/test_app
Now inside the project root directory, run the following command to create a virtual environment, for the test name it test_app:
python3.10 -m venv test_app_venv
Next, activate the virtual environment as follows:
After starting the virtual environment, you will now be in the shell prompt terminal. You will notice the name of your environment will be prefixed.
(test_app_venv) [[email protected] test_app]
By default, pip 3.10 should be installed, which is the most used package manager for Python.
In the tutorial to test the installation, Apache-Airflow was installed.
pip3.10 install apache-airflow
Remove the test application using PIP3.10.
pip3.10 uninstall apache-airflow
Proceed (Y/n)? y Successfully uninstalled apache-airflow-2.1.4
To exit the virtual environment, use the following command:
Comments and Conclusion
In the tutorial, you have learned how to install Python 3.10 for AlmaLinux 8 and create a quick virtual environment. Overall, Python 3.10 is still better, so sticking with Python 3.9 may be more desirable for the time being. For those wanting to test the latest Python, 3.10 is worth the investment to install.