Python is a high-level interpreted programming language that supports object-oriented programming and dynamic data types. It is widely used in areas such as web development, scientific computing, and artificial intelligence. CentOS 7 comes with Python 2.7 installed by default, but if you need to use Python 3.8, you can follow the steps below.
Step 1: Install Compilation Environment and Dependencies
Before installing Python, it’s necessary to install some essential compilation tools and dependencies, including GCC, openssl-devel, bzip2-devel, libffi-devel, zlib-devel, and sqlite-devel.
1
2
|
sudo yum -y groupinstall "Development Tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
|
Step 2: Download and Compile Python 3.8
- Download the source code for Python 3.8. The latest version of 3.8 is 3.8.16. If the download speed from the official website is slow, you can use a download manager and then transfer it to the server.
1
2
|
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tgz
|
- Extract the downloaded tarball.
1
|
sudo tar xzf Python-3.8.16.tgz
|
- Change into the extracted directory and configure the installation path.
1
2
3
|
cd Python-3.8.16
# Configure installation path
./configure --prefix=/usr/local/python3
|
- Compile and install Python 3.8.
1
|
sudo make && sudo make install
|
Alternatively:
The difference between make altinstall
and make install
is that make altinstall
only installs the executable files and libraries for Python 3.8, avoiding overwriting the existing Python 2.7 executable files and libraries. This prevents any impact on the system’s original Python version and makes it easier to manage multiple versions of Python. If no error messages are displayed, the installation is successful, and you will find the python3
directory under /usr/local/
.
Step 3: Add Symbolic Links
1
2
3
4
5
|
# Add a symbolic link for python3
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
# Add a symbolic link for pip3
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
|
Step 4: Check if Python 3.8 is Installed Successfully
Run the following command to check if Python 3.8 has been installed successfully:

If you see the version number for Python 3.8 displayed, it means that the installation was successful.
Conclusion
By following the steps above, you can successfully install Python 3.8 on CentOS 7 and use it for development and debugging with the python3.8
command, enabling you to work with Python 3.8 on your CentOS 7 system.