Share your love
Empower Python 3.12 Installation on Centos 7 – Easy Steps
This tutorial intends to teach you Python 3.12 Installation on Centos 7. Python 3.12 is the latest version of Python programming language which brings new features, improvements, and optimizations.
On Centos 7, the default Python version is Python 2.7. This version comes pre-installed with the operating system. However, it’s important to note that Python 2.7 has reached its end of life and is no longer actively maintained or supported by the Python Software Foundation. Also, Centos 7 has reached its end of life and doesn’t receive any updates.
So if you plan to get the latest Python version on Centos 7, you can follow the steps below on the Orcacore website.
Table of Contents
Learn Python 3.12 Installation on Centos 7
Before you start your Python setup, you must access your server as a non-root user with sudo privileges. To get the initial setup, you can check this guide on Initial Server Setup with Centos 7.
Now proceed to the following steps to start Python 3.12 Installation on Centos 7.
Step 1 – Install Required Packages For Python Setup on Centos 7
At this point, you must run the system update by using the command below:
sudo yum update -y
Then, you need some required packages and dependencies. To do this, you can run the following commands:
# sudo yum groupinstall "Development Tools" -y
# sudo yum install wget openssl-devel libffi-devel bzip2-devel -y
Once you are done, follow the steps below to download and build the latest Python from the source.
Step 2 – Download the Latest Python From the Source on Centos 7
At this point, you need to visit the Python Source Releases and get the latest source tarball package by using the following wget command:
sudo wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz
Then, extract your downloaded file with the command below:
sudo tar xvf Python-3.12.2.tgz
Now switch to your Python 3.12 directory on Centos 7:
cd Python-3.12.2
Step 3 – Build and Set up Python 3.12 Installation on Centos 7
Once you are done downloading the source package, you can easily build and install your Python 3.12. From your Python directory, run the following commands:
# sudo ./configure --enable-optimizations
# sudo make altinstall
This may take some time to complete. Once your installation is completed, verify it by checking its version:
python 3.12 --version
Output
python 3.12.2
Also, pip 3.12 must be installed on Centos 7. To check it, run the following command:
pip3.12 --version
Step 4 – Update PATH Environment Variable (Optional)
Optionally, you can update your PATH environment variable to include the directory where Python 3.12 is installed to make it easier to access. To do this, you can run the following commands:
# echo 'export PATH=/usr/local/python3.12/bin:$PATH' >> sudo ~/.bashrc
# sudo source ~/.bashrc
Step 5 – Access Python 3.12 Shell on Centos 7
At this point, you can access your Python shell with the command below:
python3.12
Now you can write a simple program to find the sum of two variables, x, and y to test your program:
x = 35
y = 75
z = x + y
print("Hello, the sum of x and y is", +z)
In your output you will see:
Conclusion
In conclusion, while Centos 7 ships with Python 2.7 as the default version, Python 3.12 Installation on Centos 7 will increase the performance and improvements to your programming language. As you can see, users can follow these general steps to install it:
- Ensure Dependencies
- Download Python 3.12
- Compile and Install
- Verify Installation
Hope you enjoy it. Also, you may like to read the following articles:
Upgrade Linux Kernel on Centos 7
Use pip to Install Python packages on Linux