Both Python 2.7 and Python 3.6 reached EOL and this requires Python developers to upgrade to newer releases of Python. Python 3.11 is the most recent release at the time of updating this article. Python is such a powerful programming language known for its easy of use. Being an interpreted language means it has an elegant syntax and dynamic typing. Most Python Libraries and interpreters are freely available in source or binary form and are freely distributed.
Python interpreter is easily extendable with new functions and data types implemented in C or C++. Python is also an extension language ideal for customizable applications. In this article we shall look at the installation process of Python 3.11 on Rocky Linux 9 / AlmaLinux 9. You need a working Rocky/Alma Linux system based on RHEL 9.
Some of the new features of Python 3.11 include:
- More Informative Error Tracebacks
- Task and exception groups to simplify working with asynchronous code.
- Faster code execution due to the Faster CPython project.
- New typing features to improve Python’s static typing support.
- Native TOML support for working with configuration files.
- Improved Type Variables – PEP 646: Variadic generics, PEP 673: self type, PEP 675: Arbitrary literal string type, PEP 681: Data class transforms, and PEP 655: Marking individual TypedDict items as required or potentially missing.
- Python 3.11 has a Faster Startup time.
- Python 3.11 supports Exception Notes to aid in adding arbitrary notes to your code.
- Supports Zero-Cost Exceptions inspired by other languages like C++ and Java.
- Negative Zero Formatting for floating-point numbers representation.
Ubuntu installation guide: How To Install Python 3.11 on Ubuntu
Install Python 3.11 on Rocky Linux 9 / AlmaLinux 9
With all the background information we now switch gear and focus on the actual installation of Python 3.11 on Rocky Linux 9 / AlmaLinux 9. Begin by ensuring the system is up-to-date.
sudo dnf -y update
If you check the version of Python3 available in the system you’ll notice it’s not the most recent.
$ python3 -V
Python 3.9.14
We shall consider two installation methods.
Method 1: Install Python 3.11 from OS repositories
At the time of updating this article, Python 3.11 packages are available on RHEL 9 based Linux systems. Install by executing the commands below.
sudo dnf install python3.11
Accept the prompt with y key to proceed with the installations.
...
Dependencies resolved.
=====================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================
Installing:
python3.11 x86_64 3.11.5-1.el9_3 appstream 26 k
Installing dependencies:
libnsl2 x86_64 2.0.0-1.el9.0.1 appstream 30 k
libtirpc x86_64 1.3.3-2.el9 baseos 92 k
mpdecimal x86_64 2.5.1-3.el9 appstream 85 k
python3.11-libs x86_64 3.11.5-1.el9_3 appstream 9.3 M
python3.11-pip-wheel noarch 22.3.1-4.el9_3.1 appstream 1.4 M
python3.11-setuptools-wheel noarch 65.5.1-2.el9 appstream 712 k
Transaction Summary
=====================================================================================================================
Install 7 Packages
Total download size: 12 M
Installed size: 47 M
Is this ok [y/N]: y
Install Python 3.11 PIP package manager.
sudo dnf install python3.11-pip
Check version of Python 3.11 installed.
$ python3.11 --version
Python 3.11.5
Python 3.11 modules can be installed with;
sudo dnf install python3.11-<module>
To get a complete list of available modules use:
sudo dnf search python3.11
Method 2: Install Python 3.11 from source
This will enable you to install the latest release of Python 3.11 on Rocky / Alma / CentOS 9. For this method, follow the steps in the next sections.
1. Install required Dependencies
Next we install the dependencies needed to build Python 3.11 on Rocky Linux / AlmaLinux 9
sudo dnf install vim wget openssl-devel bzip2-devel libffi-devel -y
It’s also recommended to install developer tools on the system.
sudo dnf -y groupinstall "Development Tools"
2. Download Python 3.11 source files
Next we need to download Python 3.11 tarball from official website.
VERSION=3.11.9
wget https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tgz
Extract the file downloaded
tar xvf Python-$VERSION.tgz
3. Install Python 3.11 on Rocky Linux 9 / AlmaLinux 9
Switch to created folder after file extraction.
cd Python-$VERSION
Run configuration script with optimizations.
./configure --enable-optimizations
Now compile and install Python 3.11 on Rocky 9 / AlmaLinux 9
sudo make altinstall
After a successful installation confirm the version of Python on the system.
$ python3.11 --version
Python 3.11.4
Do the same for pip
$ pip3.11 --version
pip 22.3.1 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)
Pip3 can be upgraded with the following commands
sudo /usr/local/bin/python3.11 -m pip install --upgrade pip
4. Install Python 3.11 modules
Python offers a vast collection of modules and packages that extend its functionality for various purposes. Here are some commonly used modules in Python. They can be installed using pip Python package management tool.
# Global install
pip3.11 install <module-name> --user
# User space install
pip3.11 install <module-name> --user
See example on installing awscli
Python module.
$ pip3.11 install awscli --user
Collecting awscli
Downloading awscli-1.27.126-py3-none-any.whl (4.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.1/4.1 MB 23.9 MB/s eta 0:00:00
Collecting botocore==1.29.126 (from awscli)
Downloading botocore-1.29.126-py3-none-any.whl (10.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.7/10.7 MB 46.5 MB/s eta 0:00:00
Collecting docutils<0.17,>=0.10 (from awscli)
Downloading docutils-0.16-py2.py3-none-any.whl (548 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 548.2/548.2 kB 36.6 MB/s eta 0:00:00
Collecting s3transfer<0.7.0,>=0.6.0 (from awscli)
Downloading s3transfer-0.6.0-py3-none-any.whl (79 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 79.6/79.6 kB 11.5 MB/s eta 0:00:00
Collecting PyYAML<5.5,>=3.10 (from awscli)
Downloading PyYAML-5.4.1.tar.gz (175 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 175.1/175.1 kB 22.9 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting colorama<0.4.5,>=0.2.5 (from awscli)
Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting rsa<4.8,>=3.1.2 (from awscli)
Downloading rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting jmespath<2.0.0,>=0.7.1 (from botocore==1.29.126->awscli)
Downloading jmespath-1.0.1-py3-none-any.whl (20 kB)
Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.29.126->awscli)
Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 35.6 MB/s eta 0:00:00
Collecting urllib3<1.27,>=1.25.4 (from botocore==1.29.126->awscli)
Downloading urllib3-1.26.15-py2.py3-none-any.whl (140 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.9/140.9 kB 23.7 MB/s eta 0:00:00
Collecting pyasn1>=0.1.3 (from rsa<4.8,>=3.1.2->awscli)
Downloading pyasn1-0.5.0-py2.py3-none-any.whl (83 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 83.9/83.9 kB 8.1 MB/s eta 0:00:00
Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore==1.29.126->awscli)
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: PyYAML
Building wheel for PyYAML (pyproject.toml) ... done
Created wheel for PyYAML: filename=PyYAML-5.4.1-cp311-cp311-linux_x86_64.whl size=45657 sha256=ef02ec772c6604154dc4d3a7b6d6eaec1fd79043a3472aa8a94d3acb2dd183bc
Stored in directory: /root/.cache/pip/wheels/2f/2f/af/a062a8f866dc44812a825da11175d50d7f255900f3b38c79b5
Successfully built PyYAML
Installing collected packages: urllib3, six, PyYAML, pyasn1, jmespath, docutils, colorama, rsa, python-dateutil, botocore, s3transfer, awscli
Successfully installed PyYAML-5.4.1 awscli-1.27.126 botocore-1.29.126 colorama-0.4.4 docutils-0.16 jmespath-1.0.1 pyasn1-0.5.0 python-dateutil-2.8.2 rsa-4.7.2 s3transfer-0.6.0 six-1.16.0 urllib3-1.26.15
To install a specific package version, use the syntax below.
python3.11 -m pip install "package_name==1.1.3"
Closure
In this article we’ve demonstrated how you can install Python 3.11 on Rocky Linux 9 / AlmaLinux 9 Linux system. We started by looking at the key features associated with Python 3.11 and later a step-by-step installation procedure. Finally, we looked at an example of using pip package manager to install a Python module. We hope this article was helpful and we would like to thank you for visiting our website.
FYI: on AlmaLinux 9 you can (now) install python311 from appstream.
`yum install python3.11` works in RockyLinux 9.3 (and possibly earlier versions too)
Thanks we shall update the article to reflect that.
`yum install python3.11` doesn’t work for Centos 8.5.2111, which `dnf update` had been done.
root@localhost~ # yum install python3.11
Updating Subscription Management repositories.
……
Error: Unable to find a match: python3.11
Try switching to CentOS Stream 8 or Rocky/AlmaLinux 8.