How to Install Python 3 on CentOS, Ubuntu and Windows?

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 andthat 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 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 python3Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile* base: centos.excellmedia.net* extras: centos.excellmedia.net* updates: centos.excellmedia.netbase | 3.6 kB 00:00:00docker-ce-stable | 3.5 kB 00:00:00extras | 2.9 kB 00:00:00updates | 2.9 kB 00:00:00Resolving 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 ResolutionDependencies Resolved==========================================================================================================================================================================Package Arch Version Repository Size==========================================================================================================================================================================Installing:python3 x86_64 3.6.8-18.el7 updates 70 kInstalling for dependencies:libtirpc x86_64 0.2.4-0.16.el7 base 89 kpython3-libs x86_64 3.6.8-18.el7 updates 6.9 Mpython3-pip noarch 9.0.3-8.el7 base 1.6 Mpython3-setuptools noarch 39.2.0-10.el7 base 629 kTransaction Summary==========================================================================================================================================================================Install 1 Package (+4 Dependent packages)Total download size: 9.3 MInstalled size: 48 MIs this ok [y/d/N]: yDownloading 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:15Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : libtirpc-0.2.4-0.16.el7.x86_64 1/5Installing : python3-setuptools-39.2.0-10.el7.noarch 2/5Installing : python3-pip-9.0.3-8.el7.noarch 3/5Installing : python3-3.6.8-18.el7.x86_64 4/5Installing : python3-libs-3.6.8-18.el7.x86_64 5/5Verifying : libtirpc-0.2.4-0.16.el7.x86_64 1/5Verifying : python3-setuptools-39.2.0-10.el7.noarch 2/5Verifying : python3-libs-3.6.8-18.el7.x86_64 3/5Verifying : python3-3.6.8-18.el7.x86_64 4/5Verifying : python3-pip-9.0.3-8.el7.noarch 5/5Installed:python3.x86_64 0:3.6.8-18.el7Dependency 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.el7Complete!$

Python 3 on CentOS 8.x

Python 3 can be installed on CentOS 8.x using. 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 python3Last 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 kTransaction Summary==========================================================================================================================================================================Upgrade 1 PackageTotal download size: 19 kIs this ok [y/N]: yDownloading 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:04Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transactionPreparing : 1/1Upgrading : python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 1/2Running scriptlet: python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 1/2Cleanup : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64 2/2Running scriptlet: python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64 2/2Verifying : python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 1/2Verifying : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64 2/2Installed products updated.Upgraded:python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64Complete!$

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 --versionPython 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 officialshould 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.

Further Reading

You can learn more about Python and its usage from its extensiveor by taking.

Next, find out how toto install Python packages.