Thursday, January 9, 2025
Google search engine
HomeGuest BlogsHow To Install Python 3.11 on CentOS 7 / RHEL 7

How To Install Python 3.11 on CentOS 7 / RHEL 7

Python is a high-level, interpreted programming language that has been adopted for varying applications development and gained immense popularity in the recent years. Python can be used in coding wide range of applications, including web development, data analysis, scientific computing, artificial intelligence, Games, and more. It is an ideal language for beginners because of its simplicity and ease of use.

Some of the factors that have contributed to its success of python as a programming language include the following:

  • It is Open Source: Being an open-source language means anyone can access and modify the code to suit their business needs.
  • Its is Object-Oriented: Python is an object-oriented language meaning everything in Python is an object.
  • It is a Cross-Platform Language: A Python code can be run on major operating systems such as Linux, Windows, and macOS.
  • Has Large Community: Python enjoys a large and active community of developers who contribute to its development and create third-party libraries and tools.
  • Interpreted Language: Python being a interpreted language means no need to compile the code before running it.
  • Extensive Libraries: There are lots of standard and third-party libraries, which makes it easy to perform a wide range of tasks in Python.
  • It is easy to Learn: Python is a popular language for beginners because it has a simple and easy-to-learn syntax.

Python is widely used in industries such as finance, healthcare, and technology, and is also popular among data scientists and researchers due to its rich set of libraries and tools for data analysis and visualization. The latest stable release of Python at the time of creating this content is Python 3.11.

Python 3.11 features and Improvements

  • More Informative Error Tracebacks
  • Faster code execution due to the Faster CPython project.
  • Task and exception groups to simplify working with asynchronous code.
  • 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.
  • Supports Zero-Cost Exceptions inspired by other languages like C++ and Java.
  • Python 3.11 supports Exception Notes to aid in adding arbitrary notes to your code.
  • Negative Zero Formatting for floating-point numbers representation.

In this article we will show our users how they can install and use Python 3.11 on CentOS 7 / RHEL 7.

Install Python 3.11 on CentOS 7 / RHEL 7

Python 3.11 is a significant release that introduces many new features and improvements to the language. In this section we will cover all the necessary steps to have Python 3.11 installed on CentOS 7 / RHEL 7 Linux system.

Step 1: Update System

This is recommended but an optional step. If you have other applications running on the system and afraid of dependencies breaking you can skip this step.

sudo yum -y update

After a successful update let’s reboot the system.

sudo systemctl reboot

Step 2: Install Python 3.11 build tools

Python 3.11 is not available official repositories of CentOS 7 / RHEL 7 repositories. We shall install it from the source code but there are dependency packages to be installed before a build process.

sudo yum -y install epel-release
sudo yum install wget make cmake gcc bzip2-devel libffi-devel zlib-devel

All Development Tools can be installed from package group with the commands below:

sudo yum -y groupinstall "Development Tools"

Confirm GCC version:

$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Step 3: Install OpenSSL 1.1 on CentOS 7 / RHEL 7

Building Python 3.11 requires a openssl 1.1.1 or newer. The version available on the system repositories is old.

Follow the steps in the guide below to install and configure OpenSSL 1.1.1 on CentOS 7 / RHEL 7:

Step 4: Install Python 3.11 on CentOS 7 / RHEL 7

Building Python 3.11 requires a openssl 1.1.1 or newer. The version available on the system repositories is old.

After installing OpenSSL 1.1.1, verify by checking the version:

$ openssl version
OpenSSL 1.1.1t  7 Feb 2023

Let’s download Python 3.11 source:

wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz

Extract downloaded archive

tar xvf Python-3.11.4.tgz

Navigate into created directory.

cd Python-3.11*/

Configure the build

LDFLAGS="${LDFLAGS} -Wl,-rpath=/usr/local/openssl/lib" ./configure --with-openssl=/usr/local/openssl 
make

Install Python 3.11 on CentOS 7 / RHEL 7

sudo make altinstall

After installation, you can check the installed version of Python 3.11 with the command:

$ python3.11 --version
Python 3.11.4

Verify OpenSSL libs work

$ python3.11
Python 3.11.4 (main, May 24 2023, 12:20:28) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.1.1t  7 Feb 2023'
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> Ctrl-D

Step 5: Install Python modules using Pip3.11

Pip is installed during Python installation. Check the pip version installed by running this command.

$ pip3.11 --version
pip 22.3.1 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)

You can upgrade your Pip package to latest release:

pip3.11 install --upgrade pip

Now use PIP to install any module. The command to use has the syntax:

sudo pip3.11 install <module-name>

For example:

sudo pip3.11 install awscli

Conclusion

In conclusion, Python’s versatility, simplicity, and its capabilities make it an excellent choice for anyone looking to learn or adopt a programming language for various applications and projects. There are numerous libraries, frameworks, and tools that enables you to build innovative applications efficiently.

RELATED ARTICLES

Most Popular

Recent Comments