Enjoy Sharing Technology!

Software,Develope,Devops, Security,TroubleShooting

Monday, May 16, 2022

How to Install Python 3 on CentOS 8

 

How to Install Python 3 on CentOS 8

Unlike other Linux distributions, CentOS 8 does not come with a version of Python installed. Currently Python 3.9 is the latest major version of Python. This guide shows two options for installing Python 3 on CentOS 8:

How to Install Python 3.9

You need to build Python 3.9 from source to install it on CentOS 8.

  1. Download the dependencies to build the package:

     sudo dnf groupinstall 'development tools'
     sudo dnf install wget openssl-devel bzip2-devel libffi-devel
    
  2. Download Python version 3.9:

     sudo curl https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz -O
    
  3. Extract the Python package:

     tar -xvf Python-3.9.1.tgz
    
  4. Change into the Python directory:

    cd Python-3.9.1
    
  5. Run the configuration script and run the build process:

     sudo ./configure --enable-optimizations
     sudo make install
    
    Note
    If you have an already existing Python binary installed at /usr/bin/python or /usr/bin/python3, you should run sudo make altinstall instead.
  6. After the installation is finished, you can run the command python3 -V and verify the installation:

    python3 -V
    

    The output looks like this:

    Python 3.9.1

How to Install Python 3.6

If you do not need the latest version of Python, you can install Python 3.6 using the CentOS repository. This version is included in the CentOS repository by default. While this installation method is easier than the previous from source method, it is not the latest version. Install version 3.6 by running the following command:

sudo dnf install python3

If you haven’t installed any other version of Python, you can verify this installation by typing:

python3 -V

And the shell returns:

Python 3.6.8

Additional Information

Installing multiple versions of Python 3 is not recommended. It’s best to manage multiple versions with tools like pyenv or anaconda .

If you installed Python 3.9 by compiling from source, the installed binary is located at /usr/local/bin/python3. If you installed Python 3.8 from the CentOS package repository, the installed binary is located at /usr/bin/python3.

How to Install Python 2

You may require Python 2 as a dependency for older code or software. If this is the case, you can install it with the following command:

sudo dnf install python2

Run python2 -V to check the version:

python2 -V

The output looks like the following:

Python 2.7.17

It’s important to remember that Python2 is no longer supported by the Python foundation. Therefore, there are no new updates or fixes. Applications are making the switch to Python 3, and distributions like Ubuntu 20.04 and CentOS 8 are no longer shipping with Python 2 by default.


Share:

Search This Blog

Weekly Pageviews

Translate