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 field of data analysis and machine learning.

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

Python currently offers both Python 2.x and Python 3.x, which are not fully compatible with each other and have a few differences. Therefore, choosing to use any of them should be a planned decision based on your current environment and needs. Most Linux distributions come pre-installed with a version of Python due to its widespread use in OS libraries and software.

This article will cover installing Python 3 on CentOS, Ubuntu and Windows platforms. Python 3 can be installed along with Python 2, but you must be careful about specifying the system's default Python interpreter.

Python 3 on CentOS 6.x/7.x

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

$ sudo yum install python3

Confirm by pressing "y" when prompted:

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

The Python 3 install log on CentOS 7 is 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 the DNF package manager. Use the command below to start installing Python 3:

$ sudo dnf install python3

Confirm by pressing "y" when prompted:

Is this ok [y/N]: y

A snippet of the Python 3 installation log 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!$

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

Newer Ubuntu systems already have Python 3 installed. If it was removed for some reason and you need to install it explicitly, use the following command:

$ sudo apt install python3

Check out Python 3 on Linux

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

$ python3 --versionPython 3.8.6$

Python 3 в Windows

On Windows, Python 3 can be installed using a simple installation wizard from the official Python website. The default installer offered on the official download page should be sufficient for most purposes, unless you need to select a different version or architecture of Python.

The latest version available at the time of this writing is 3.9.1.

For a 64-bit architecture, the downloaded Python installer will be named something like this: python-3.xx-amd64.exe.

  • Run the installer by running the downloaded .exe file.
  • The default options selected for the installer should work. However, you have the option to change the installation location and components using the "Customize installation" option.
  • There is also an option to install Python 3 for all users or just for your specific Windows user account.
  • Finally, there is an option to add Python 3 to the Windows PATH environment variable, which will allow you to use Python 3 from the Windows command line from any directory.
  • After confirming all settings, click "Install Now" to continue installing Python 3 with default options.
  • The installation dialog will show the progress of the installation. Wait for completion.
  • Once the installation is complete, you should be able to find the Python 3.x icon in the Windows start menu, which opens the Python 3 Interactive CLI.
  • The Python 3 interactive command line interface allows you to write and execute Python commands interactively. For example, simple Hello World Python code can be written using the print command. Because it is an interactive command line interface, the command is interpreted at the same time and the output is immediately printed.

To practice writing code, you should get a Python IDE.

Further Reading

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

Related posts