Installation guides

Installing Python on RHEL

Step-by-Step Guide

  1. Update the Package Index
    Open a terminal and update the package index to ensure you have the latest information about available packages:
   sudo yum update -y
  1. Install Python
    RHEL typically comes with Python pre-installed. However, you can install the latest versions of Python using the yum package manager:
   sudo yum install python3 -y

This command installs Python 3.

  1. Verify Python Installation
    Check the Python version to ensure it is installed correctly:
   python3 --version

You should see the Python version information displayed.

  1. Verify pip Installation
    Check if pip, the Python package installer, is installed:
   pip3 --version

If pip is not installed, you can install it using:

   sudo yum install python3-pip -y
  1. Install Virtualenv (Optional)
    It’s a good practice to use virtual environments for your Python projects. Install virtualenv using pip:
   sudo pip3 install virtualenv
  1. Create a Virtual Environment (Optional)
    Create a new virtual environment for your project:
   virtualenv venv

Activate the virtual environment:

   source venv/bin/activate

Your command prompt should change to indicate that the virtual environment is active.

  1. Install Packages with pip
    You can now install Python packages within your virtual environment using pip. For example, to install Flask, a popular web framework, use:
   pip install flask
  1. Deactivate the Virtual Environment
    When you are done working in the virtual environment, deactivate it:
   deactivate
  1. Create a Simple Python Script
    To test your Python installation, create a simple Python script:
   nano hello.py

Add the following code to the file:

   print("Hello, World!")

Save and close the file.

  1. Run the Python Script
    Execute the script to ensure Python is working correctly:
    bash python3 hello.py
Other Recent Posts