Python modules for Red Hat-based Linux operating systems like Red Hat, Fedora, Rocky Linux, and CentOS are hosted on yum repositories.
This article will show how to install and remove the Python requests module using YUM or DNF package managers. We will also discuss how to install requests using pip.
The requests package is used to send and receive HTTP requests using Python.
Installing requests using yum
The requests library can be installed on Red Hat-based Linux devices by following these steps.
Step 0: Open the terminal application and run the following command to update the yum database
1 |
sudo yum makecache |
Step 1: Once yum repositories are updated, we can now install requests as python-requests by running
1 |
sudo yum -y install python-requests |
Note: You can install python-requests similarly, using DNF package manager instead of yum. Just replace yum with dnf in the above commands.
Uninstalling requests installed with yum
If you want to uninstall requests that were installed with yum or dnf you can do that by using the command
1 |
sudo yum remove python-requests |
or
1 |
sudo dnf remove python-requests |
Note: The yum repository contains fewer Python packages than the official Python repository – Python Packages Index (PyPI). Moreover, Python packages hosted on PyPI are generally more updated than the ones available in yum repositories (For example, by the time of writing this article, PyPI has the latest requests package being version 2.28.1, but yum has 2.27.1). For this reason, you might prefer to install requests from PyPI using pip.
Bonus: Installing requests using pip
PyPI packages can be installed using pip, but pip is not installed by default in Red Hat-based systems. You can install pip using yum or dnf from the terminal using the following command.
1 |
sudo yum -y install python3-pip |
or
1 |
sudo dnf -y install python3-pip |
If you are running Python 2 you need to install python2-pip. Once pip is installed, you can use it to install requests in Fedora, CentOS, Rocky Linux, or RedHat by running the following on the terminal
1 |
pip install requests |
You can update requests using pip by issuing –upgrade option (or -U shorthand) as follows
1 |
pip install --upgrade requests |
And Python requests can be removed by running
1 |
pip remove requests |