In Python, the web library named “requests” is utilized to exchange requests on the web. The “requests” library provides human-friendly and simple HTTP requests. To use “requests” in Python script, the module must be imported at the program’s start using the keyword “import”. In Python, the error “ModuleNotFoundError” occurs when the “requests” module is imported without being installed.
This article will demonstrate various reasons and solutions for “ModuleNotFoundError: no module named request” in Python using the following aspects:
- Reason: “requests” Module Not Installed
- Solution 1: Install “requests” Module (For Windows)
- Solution 2: Install “requests” Module (For Linux)
- Verification of “request” Module in Python
So, let’s get started!
Reason: “requests” Module Not Installed
Primarily, this error occurs when the user tries to import the “requests” module without installing it into the Python environment. The error is displayed in the following snippet:
The above snippet shows that the “requests” module is not installed in our system.
Solution: Install the “requests” Module (For Windows)
To resolve this error, the “requests” module must be installed in Python. Here are the steps you need to follow:
Step 1: Open Command Prompt Terminal (CMD)
The first step is to open the command prompt terminal of your window by following the below snippet:
Step 2: Install the “requests” Module Using the pip
After opening the command prompt terminal, type the given below command and press enter to execute:
> pip install requests
The “requests” module is successfully installed in Python, as shown in the above output.
If you get a permission error during installation, then use the given below command:
> pip install requests --user
To install the “requests” module in Anaconda and Jupyter Notebook, use the given below command in their respective environment:
# for Anaconda
conda install -c anaconda requests
# for Jupyter Notebook
!pip install requests
Note: if the module is installed in the wrong environment. If you encounter the “ModuleNotFoundError”, you can follow these above steps by choosing the correct environment.
Solution 2: Install the “requests” Module (For Linux)
To install the “request” module in Linux using the “pip” package manager, you first need to install “pip” if you don’t already have it in the system, click here to read out the installation of pip on Linux:
After installing the Python “pip” package manager now you can type the given below command in terminal:
$ pip install requests
Verification of “request” Module in Python
To check whether the “request” module is successfully installed in our system or not type the given below command in the respective shell:
> pip show requests
The above snippet shows the “requests” module version and summary that is installed in Python.
Conclusion
In Python, the “ModuleNotFoundError: No module named requests” occurs when a user tries to import the “requests” module in the program without installing it. To resolve this error, install the “requests” module using the pip package manager. After that, import the “requests” module, and the error will be resolved. This write-up has delivered different reasons and solutions for the “No module named request” error in Python.