yum install python3 with code examples

Introduction:

Python is one of the most popular programming languages in the world as it is easy to learn and its syntax is simple and readable. It is a versatile, high-level programming language that has become an important tool for data analysis, machine learning, and web development.

In this article, we will be discussing how to install Python3 on various operating systems using the 'yum' package manager, which is the default package manager for several Linux distributions.

Installing Python3 on CentOS/RHEL:

  1. Open the terminal and log in as root or a user with root privileges.

  2. Update the system package list by running the following command:

    yum -y update

  3. Install Python3 by running the following command:

    yum -y install python3

  4. Verify that Python3 is installed by running the following command:

    python3 –version

    This command should return the version number of the installed Python3 binary, for example: Python 3.6.8

Installing Python3 on Fedora:

  1. Open the terminal and log in as root or a user with root privileges.

  2. Update the system package list by running the following command:

    dnf -y update

  3. Install Python3 by running the following command:

    dnf -y install python3

  4. Verify that Python3 is installed by running the following command:

    python3 –version

    This command should return the version number of the installed Python3 binary, for example: Python 3.9.6

Examples:

After installing Python3, let's run some basic Python code to make sure everything is working correctly.

Open a text editor such as nano or vim and create a file called 'hello_world.py' with the following code:

  print("Hello, world!")

Save the file and run it using the following command:

  python3 hello_world.py

This should print the message "Hello, world!" on the terminal.

We can also install Python packages using the 'yum' package manager. For example, let's install the 'numpy' package which is a popular package for scientific computing.

To install numpy, run the following command:

  yum -y install python3-numpy

After installing numpy, let's run some code to make sure it is working correctly.

Open a text editor and create a file called 'numpy_test.py' with the following code:

  import numpy as np
  a = np.array([1, 2, 3])
  print(a)

Save the file and run it using the following command:

  python3 numpy_test.py

This should print the numpy array '[1, 2, 3]' on the terminal.

Conclusion:

In this article, we discussed how to install Python3 on different Linux distributions using the 'yum' package manager. We also ran some basic Python code and installed a Python package 'numpy' using 'yum'. Installing Python3 is easy and straightforward, and once installed, it opens up a wide range of possibilities for programming and data analysis.

let's discuss the topics covered in a bit more detail:

  1. Installing Python3 on CentOS/RHEL:

CentOS/RHEL is a popular Linux distribution used in enterprise environments. To install Python3 on CentOS/RHEL, you can use the 'yum' package manager. The 'yum' package manager is a command-line utility that automatically downloads and installs software packages from individual repositories. To install Python3, you need to update the system package list and then run the command 'yum -y install python3'. You can verify the installation by running 'python3 –version' which should return the version number of the installed Python3 binary.

  1. Installing Python3 on Fedora:

Fedora is a popular Linux distribution known for its cutting-edge technology. To install Python3 on Fedora, you can use the 'dnf' package manager. 'dnf' is a modern and improved version of 'yum' and is used in Fedora and newer versions of CentOS/RHEL. To install Python3, you need to update the system package list and then run the command 'dnf -y install python3'. You can verify the installation by running 'python3 –version' which should return the version number of the installed Python3 binary.

  1. Examples:

After installing Python3, we ran some basic Python code to confirm that everything is working correctly. The 'hello_world.py' script is a simple Python program that prints the message "Hello, world!" on the terminal. We also installed the 'numpy' package using 'yum' which is a popular package for scientific computing. Once installed, we wrote a small Python program that imported the 'numpy' package and created a simple array that printed on the terminal.

In conclusion, Python is a versatile language that can be used for scripting, web development, data analysis, and machine learning. By installing Python3 using the 'yum' (or 'dnf') package managers, we can use the latest version and take advantage of the available packages and tools. Knowing how to set up a Python environment is a crucial skill for developers and data analysts alike.

Popular questions

Q1. What is yum?
A1. Yum is the default package manager on many Linux distributions, including CentOS, Red Hat Enterprise Linux (RHEL), and Fedora. It is a command-line utility that automatically downloads and installs software packages from individual repositories.

Q2. How to install Python3 using yum?
A2. To install Python3 using yum, you need to update the system package list and then run the command 'yum -y install python3'.

Q3. How to install Python3 using dnf?
A3. To install Python3 using dnf, you need to update the system package list and then run the command 'dnf -y install python3'.

Q4. What is the purpose of the numpy package?
A4. The numpy package is a popular package for scientific computing and is used for mathematical operations on large, multi-dimensional arrays and matrices.

Q5. How can you verify the installation of Python3 on the system?
A5. You can verify the installation of Python3 on the system by running the command 'python3 –version' which should return the version number of the installed Python3 binary.

Tag

Programming

As a senior DevOps Engineer, I possess extensive experience in cloud-native technologies. With my knowledge of the latest DevOps tools and technologies, I can assist your organization in growing and thriving. I am passionate about learning about modern technologies on a daily basis. My area of expertise includes, but is not limited to, Linux, Solaris, and Windows Servers, as well as Docker, K8s (AKS), Jenkins, Azure DevOps, AWS, Azure, Git, GitHub, Terraform, Ansible, Prometheus, Grafana, and Bash.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top