Modulenotfounderror: no module named requests

In this article, we will learn how to solve or fix Modulenotfounderror: No Module Named Requests.

Also, in Python programming language, the “ModuleNotFoundError: No module named ‘requests’ “ will appears.

Why does the error occur?

The no module named requests error occur because If we forgot to install the “requests module” before importing or installing it in the wrong environment.

How to solve the ModuleNotFoundError: No module named ‘requests’?

To fix the error we will use different ways.

Open your project root directory we need to install the module by typing this command:

In a virtual environment or using Python 2

We will use this command for installing in Python 2.

pip install requests

For python 3

We will use this command for installing in Python 3.

pip3 install requests

For getting permissions error

We will use this command for installing in getting permissions error.

sudo pip3 install requests
pip install requests –user

When you don’t have pip in your PATH environment variable

We will use this command for installing if you don’t have pip in your PATH environment variable.

python -m pip install requests

For python 3

We will use this command for installing in Python 3

python3 -m pip install requests

Using py alias in Windows

We will use this command for installing using py alias in Windows.

py -m pip install requests

For Ubuntu/Debian

We will use this command for installing for Ubuntu/Debian.

sudo apt-get install python3-requests

For CentOS

We will use this command for installing in CentOS.

sudo yum install python-requests

For Anacondas

We will use this command for installing in Anacondas.

conda install -c anaconda requests

For Jupyter Notebook

We will use this command for installing Jupyter Notebook.

!pip install requests

The Typical Reasons that the Error Appears

The “ModuleNotFoundError: No module named ‘requests'” appears for numerous reasons:

  • There is no requests module installed in your system. To install it, type this command: pip install requests
  • Installing the module in a various Python version than the one you’re currently using.
  • Installing the module globally and it is not installed in your virtual environment.
  • Executing the IDE which is not the correct version of Python.
  • Naming your module requests.py to replace the official module
  • Defining the requests variable as a shadow of the imported variable.

When the error will continue, look at your Python version and to insure you are installing the module using the correct version of python.

Type this command to know your python version:

python –version

After you type the command the output will be like this:

python version

Check if the package is installed

We will check if the requests module is installed by executing the pip show requests command.

pip3 show requests

The pip show requests command whether the package which is not installed or it will show a lot of information about the module, along with the location where the package is installed.

Check if the package is installed

Conclusion

To conclude, in this article we already learned how to fix or solve the Modulenotfounderror: No Module Named Requests.

Also, we already know how to install it in Windows, UBUNTU, CentOS, ANACONDAS, and JUPYTER NOTEBOOK.

Leave a Comment