• Get application security done the right way! Detect, Protect, Monitor, Accelerate, and more…
  • Python is an open, powerful, interpreted, and easy to learn programming language that supports multiple platforms. It is one of the most preferred programming languages in the fields of Data Analytics and Machine Learning.

    It offers an extensive set of in-built and portable libraries that can be easily included to extend your Python project. Further, it has broad support for object-oriented and functional programming practices of software engineering.

    Python currently offers both Python 2.x and Python 3.x, which are not fully compatible with each other and have several differences. Hence the choice of using either of them should be a planned decision based on your current environment and needs. Most of the Linux distributions come pre-installed with some Python version due to its extensive use in OS libraries and software.

    This article will cover the installation of Python 3 on CentOS, Ubuntu, and Windows-based platforms. Python 3 can be installed along with Python 2, but you need to be careful in specifying the system’s default Python interpreter.

    Python 3 on CentOS 6.x/7.x

    For CentOS 6.x/7.x or RHEL based distribution, you can install Python 3 using yum.

    $ sudo yum install python3

    When prompted, please confirm by pressing ‘y’:

    Is this ok [y/d/N]: y

    Python 3 installation log on CentOS 7 is given below:

    $ sudo yum install python3
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * base: centos.excellmedia.net
    * extras: centos.excellmedia.net
    * updates: centos.excellmedia.net
    base | 3.6 kB 00:00:00
    docker-ce-stable | 3.5 kB 00:00:00
    extras | 2.9 kB 00:00:00
    updates | 2.9 kB 00:00:00
    Resolving Dependencies
    --> Running transaction check
    ---> Package python3.x86_64 0:3.6.8-18.el7 will be installed
    --> Processing Dependency: python3-libs(x86-64) = 3.6.8-18.el7 for package: python3-3.6.8-18.el7.x86_64
    --> Processing Dependency: python3-setuptools for package: python3-3.6.8-18.el7.x86_64
    --> Processing Dependency: python3-pip for package: python3-3.6.8-18.el7.x86_64
    --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python3-3.6.8-18.el7.x86_64
    --> Running transaction check
    ---> Package python3-libs.x86_64 0:3.6.8-18.el7 will be installed
    --> Processing Dependency: libtirpc.so.1()(64bit) for package: python3-libs-3.6.8-18.el7.x86_64
    ---> Package python3-pip.noarch 0:9.0.3-8.el7 will be installed
    ---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed
    --> Running transaction check
    ---> Package libtirpc.x86_64 0:0.2.4-0.16.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==========================================================================================================================================================================
    Package Arch Version Repository Size
    ==========================================================================================================================================================================
    Installing:
    python3 x86_64 3.6.8-18.el7 updates 70 k
    Installing for dependencies:
    libtirpc x86_64 0.2.4-0.16.el7 base 89 k
    python3-libs x86_64 3.6.8-18.el7 updates 6.9 M
    python3-pip noarch 9.0.3-8.el7 base 1.6 M
    python3-setuptools noarch 39.2.0-10.el7 base 629 k
    
    Transaction Summary
    ==========================================================================================================================================================================
    Install 1 Package (+4 Dependent packages)
    
    Total download size: 9.3 M
    Installed size: 48 M
    Is this ok [y/d/N]: y
    Downloading packages:
    (1/5): python3-3.6.8-18.el7.x86_64.rpm | 70 kB 00:00:00
    (2/5): libtirpc-0.2.4-0.16.el7.x86_64.rpm | 89 kB 00:00:00
    (3/5): python3-setuptools-39.2.0-10.el7.noarch.rpm | 629 kB 00:00:01
    (4/5): python3-pip-9.0.3-8.el7.noarch.rpm | 1.6 MB 00:00:06
    (5/5): python3-libs-3.6.8-18.el7.x86_64.rpm | 6.9 MB 00:00:15
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total 613 kB/s | 9.3 MB 00:00:15
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
    Installing : libtirpc-0.2.4-0.16.el7.x86_64 1/5
    Installing : python3-setuptools-39.2.0-10.el7.noarch 2/5
    Installing : python3-pip-9.0.3-8.el7.noarch 3/5
    Installing : python3-3.6.8-18.el7.x86_64 4/5
    Installing : python3-libs-3.6.8-18.el7.x86_64 5/5
    Verifying : libtirpc-0.2.4-0.16.el7.x86_64 1/5
    Verifying : python3-setuptools-39.2.0-10.el7.noarch 2/5
    Verifying : python3-libs-3.6.8-18.el7.x86_64 3/5
    Verifying : python3-3.6.8-18.el7.x86_64 4/5
    Verifying : python3-pip-9.0.3-8.el7.noarch 5/5
    
    Installed:
    python3.x86_64 0:3.6.8-18.el7
    
    Dependency Installed:
    libtirpc.x86_64 0:0.2.4-0.16.el7 python3-libs.x86_64 0:3.6.8-18.el7 python3-pip.noarch 0:9.0.3-8.el7 python3-setuptools.noarch 0:39.2.0-10.el7
    
    Complete!
    $

    Python 3 on CentOS 8.x

    Python 3 can be installed on CentOS 8.x using DNF package manager. Use the below command to start Python 3 install:

    $ sudo dnf install python3

    When prompted, please confirm by pressing ‘y’:

    Is this ok [y/N]: y

    Log snippet of Python 3 install on CentOS 8 is shown below:

    $ sudo dnf install python3
    Last metadata expiration check: 6:25:17 ago on Friday 11 December 2020 12:44:46 PM IST.
    Package python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64 is already installed.
    Dependencies resolved.
    ==========================================================================================================================================================================
    Package Architecture Version Repository Size
    ==========================================================================================================================================================================
    Upgrading:
    python36 x86_64 3.6.8-2.module_el8.3.0+562+e162826a AppStream 19 k
    
    Transaction Summary
    ==========================================================================================================================================================================
    Upgrade 1 Package
    
    Total download size: 19 k
    Is this ok [y/N]: y
    Downloading Packages:
    python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64.rpm 5.6 kB/s | 19 kB 00:03
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total 4.6 kB/s | 19 kB 00:04
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
    Preparing : 1/1
    Upgrading : python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 1/2
    Running scriptlet: python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 1/2
    Cleanup : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64 2/2
    Running scriptlet: python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64 2/2
    Verifying : python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 1/2
    Verifying : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64 2/2
    Installed products updated.
    
    Upgraded:
    python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64
    
    Complete!
    $

    Python 3 on Ubuntu

    On an OS running Ubuntu/Debian, we can use apt or apt-get to get Python 3.

    Newer Ubuntu systems already have Python 3 installed. In case it has been removed for some reason, and you need to install it explicitly, use the below command:

    $ sudo apt install python3

    Verify Python 3 on Linux

    Python 3 can be easily checked from Linux Terminal. To check the installed version, use:

    $ python3 --version
    Python 3.8.6
    $

    Python 3 on Windows

    On Windows, Python 3 can be installed with a simple wizard-based installer from the official Python site. The default installer offered on the official download page should be good enough for most purposes unless you need to choose a different Python version or architecture.

    The latest available version as of writing this article is 3.9.1.

    For 64-bit architecture, your downloaded Python installer will be named something like python-3.x.x-amd64.exe.

    • Launch the installer by executing the downloaded exe file.
    • Default options selected for the installer should be good to go. However, you have the option of modifying installation location and components with the Customize installation option.
    • There’s also an option to install Python 3 for all users or just for your specific Windows user account.
    • Finally, there’s an option to add Python 3 in the Windows PATH environment variable, which would allow you to use Python 3 from Windows Command Prompt from any directory location.
    • Once all settings are confirmed, click Install Now to proceed with Python 3 installation using default options.

    • Installation dialog will show the installation progress. Please wait for it to complete.

    • On completion of the installation, you’ll be able to find Python 3.x icon in Windows’ Start Menu, which opens up Python 3 Interactive CLI.

    • Interactive Python 3 CLI allows you to write and execute Python commands interactively. As an example, a simple Hello World code in Python can be written using the print command. Since it is an interactive CLI, the command is interpreted simultaneously, and the output gets printed immediately.

    To practice code, you should get Python IDE.

    Further Reading

    You can learn more about Python and its usage from its extensive documentation or by taking online courses.