Python

ModuleNotFoundError: No module Named ‘requests’

Requests is a free and open-source HTTP library for Python. It offers clean, minimal, and efficient standards for performing HTTP requests in Python.

It is also fast and very beginner-friendly as it abstracts complex HTTP operations behind sweet and straightforward functions.

This article will discuss how to resolve the ModuleNotFound error when importing the requests library in Python.

Error Source

The ModuleNotFound error occurs when you attempt to import a non-existent module.

The requests library is not part of the Python standard library. This means you have to install it in your environment before using it.

You can do it with a simple command as shown in the instructions below:

Install Requests on Windows

On Windows, open your terminal session and run the command below:

$ pip install requests

Or

$ pip3 install requests

Or

$ conda install -c anaconda requests

The above commands should fetch the requests library and install it in your environment.

Install Requests on Linux

On Linux, use the commands as shown below for your specific distribution.

Note that you have to ensure you have the Python and Pip installed before running the commands below.

Debian-based Distros:

$ sudo pip install requests

$ sudo pip3 install requests

You can also install requests using apt as shown in the command below:

$ sudo apt-get install python-requests

$ sudo apt-get install python3-requests

On REHL systems, run the commands:

$ sudo pip install requests

or

$ sudo pip3 install requests

To use your package manager, run the commands:

$ sudo yum install python-requests

or

$ sudo yum install python3-requests

With that, you should have the requests library installed in your environment.

Terminate

This article illustrated practical methods to resolve the ModuleNotFound error when importing the requests module in Python.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list