Install Python 3.11 on Centos 7 | Best Program Language

Posted on

Install Python 3.11 on Centos 7 | Best Program Language

This article, brought to you by Orcacore, will guide you through the process of installing Python 3.11 on Centos 7. Released on October 24, 2022, Python 3.11 boasts enhanced speed and improved usability, making it a significant upgrade after seventeen months of dedicated development.

As with every new iteration, Python 3.11 includes a host of improvements and features.

  • (Original Article’s Features – No specific features were listed in the original article, so this section is intentionally left blank, but it would ideally list key new features.)

The current stable version is 3.11.1. This tutorial will provide a step-by-step guide to installing Python 3.11 on Centos 7.

To proceed, ensure you have root or sudo privileges on your Centos 7 server. If needed, refer to our guide on Initial Server Setup Centos 7 for assistance.

Centos 7 Python 3.11 Setup

First, update your package index:

sudo yum update -y

Install Python Dependencies

Install the necessary packages using the following command:

# sudo yum groupinstall "Development Tools" -y
# sudo yum install wget openssl-devel libffi-devel bzip2-devel -y

Download Python 3.11

Download Python 3.11.1 from the Python Releases page using wget:

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

Extract the downloaded archive:

sudo tar xvf Python-3.11.1.tgz

Navigate to the extracted directory:

cd Python-3.11.1

Build and Install Python 3.11

Configure the installation:

./configure --enable-optimizations

Build Python:

sudo make altinstall

This process may take a while.

Verify Python and pip 3.11 Installation on Centos 7

Verify the installation by checking the Python version:

python3.11 --version

The output should be similar to:

Centos 7 Python 3.11

Check the pip version:

pip3.11 --version

The output should resemble:

pip3.11 Centos 7

This confirms a successful installation of Python 3.11 on Centos 7.

Access Python shell on Centos 7

Access the Python shell using:

python3.11

Create a Test Program

Test the installation with a simple program:

x = 35
y = 75
z = x + y
print("Hello, the sum of x and y is", +z)

The output will be:

Hello, the sum of x and y is 110

Conclusion

You have now successfully installed Python 3.11 on Centos 7. This allows you to leverage the performance improvements and features of the latest Python version. While CentOS 7 comes with an older Python version, manually installing Python 3.11 ensures compatibility with modern applications.

Hope you found this guide helpful. You might also be interested in:

How To Install Wekan Server on Centos 7

Enable RPM Fusion Repository on Centos 7

How To Install Postman on Centos 7

How To Install Tor Browser on Centos 7

Alternative Installation Methods for Python 3.11 on Centos 7

While the above method details compiling from source, two other popular methods exist for installing Python 3.11 on Centos 7: using a software collection (SCL) or utilizing a third-party repository like IUS Community.

1. Using Software Collections (SCL)

Software Collections (SCL) allow you to install multiple versions of software on the same system without conflicts. This is particularly useful when you need to maintain compatibility with older applications that require a specific Python version while still having access to the latest features.

Explanation:

SCLs work by providing a parallel set of libraries and executables in a separate directory. When you activate an SCL, the environment variables are modified to point to the SCL’s version of the software. This allows you to run different versions of the same software without interfering with the system’s default packages.

Installation Steps:

  1. Install the SCL repository:

    sudo yum install centos-release-scl
  2. Search for available Python SCLs (Optional – might not have 3.11 directly):

    yum search rh-python

    Unfortunately, at the time of writing, an official SCL for Python 3.11 may not be directly available. If a rh-python311 package exists, you can install it directly. If not (more likely), the source compilation method outlined earlier becomes more practical, or consider the IUS Community repository.

  3. If an SCL is available (hypothetically rh-python311), install it:

    sudo yum install rh-python311
  4. Activate the SCL:

    scl enable rh-python311 bash

    This will open a new shell with the environment configured to use Python 3.11 from the SCL. To make it permanent, you’d need to modify your user’s .bashrc file.

  5. Verify the installation:

    python --version

Advantages:

  • Allows multiple Python versions to coexist.
  • Reduces the risk of breaking system dependencies.

Disadvantages:

  • Requires activating the SCL to use the installed Python version.
  • Official SCLs for the very latest Python versions might lag behind the release date.

2. Using the IUS Community Repository

The IUS Community Project provides updated packages for Enterprise Linux distributions, including CentOS. While not officially supported by Red Hat, it’s a well-regarded and commonly used repository for accessing newer software versions.

Explanation:

The IUS repository offers RPM packages built specifically for CentOS. Adding this repository to your system allows you to install software using yum as you would with standard CentOS packages.

Installation Steps:

  1. Install the IUS repository:

    sudo yum install https://repo.ius.io/ius-release-el7.rpm
  2. Search for available Python packages:

    yum search python311

    IUS may provide packages like python311u and python311u-pip. The "u" suffix often indicates a package from IUS.

  3. Install Python 3.11 and pip:

    sudo yum install python311u python311u-pip
  4. Verify the installation:

    python3.11 --version
    pip3.11 --version

Advantages:

  • Easy installation using yum.
  • Provides pre-built packages, eliminating the need for compilation.

Disadvantages:

  • Not officially supported by Red Hat. Use with caution and at your own risk.
  • Packages may not always be available immediately after a new Python release.

Code Example (Python 3.11 – same as original):

Regardless of the installation method chosen (compiling from source, SCL, or IUS), the Python code you write will remain the same. Here’s a reminder of the test program:

x = 35
y = 75
z = x + y
print("Hello, the sum of x and y is", +z)

This program demonstrates basic arithmetic operations and printing to the console, which can be used to verify that Python 3.11 on Centos 7 is functioning correctly.

In conclusion, while compiling from source provides the most control, using SCLs or the IUS Community repository offer alternative methods for installing Python 3.11 on Centos 7, each with its own advantages and disadvantages. Choose the method that best suits your needs and risk tolerance.

Leave a Reply

Your email address will not be published. Required fields are marked *