While are you forget to install the requests module before importing it, if you install it in an incorrect environment. Then you will face ModuleNotFoundError: No module named ‘requests’, this error.
In this article, we will discuss about this ModuleNotFoundError: No module named ‘requests’ error in Python. And how to resolve the error all the possible solutions with examples.
How ModuleNotFoundError: No module named ‘requests’ Error Occurs?
Most of the time you get this error when trying to import Requests without installing the module using pip.
ImportError: No module named requests
How To Fix ModuleNotFoundError: No module named ‘requests’ Error?
There are different ways to fix ModuleNotFoundError: No module named ‘requests’ this error. Let us take a look at every solution.
- How To Solve ModuleNotFoundError: No module named ‘requests’ Error?
For the solve this error first you have to check which version of python are you using. Then install the requests module is using pip. If you are using python3 then you can install the request package By just running this command: pip3.10 install requests And If you are using python2 then follow the step below. Now, I hope your error will be solved.
Solution 1: Install the Request package
The recommended way to install the requests module is using pip. If you are using python2 then run this command.
pip install requests
And if you are using python3 then follow this command.
pip3 install requests
If you don’t have pip in your PATH environment variable. Then run this command.
python -m pip install requests
For python3 run this command.
python3 -m pip install requests
After install the requests package, try import like this
import requests res = requests.get('your_url_here') print(res)
Solution 2: Check requests is Installed or Not
If you are still getting this error then check the requests module is installed or not. Run below the command.
# 👇️ check if you have requests installed pip3 show requests # 👇️ if you don't have pip setup in PATH python3 -m pip show requests
After run this command it will show requests module is not installed. Then requests install by run this command.
pip3 install requests OR python3 -m pip install requests
I hope now your error will be solved.
Solution 3: Install For Virtual Environment
If you are using a virtual environment then you have to install the requests for your virtual environment. First, you have to create a new virtual environment if you don’t have.
python3 -m venv venv
Then activate it by running this command.
# 👇️ activate on Unix or MacOS source venv/bin/activate # 👇️ activate on Windows venv\Scripts\activate.bat
Then install requests in virtual environment
pip install requests
Now, I hope your error will be solved.
In this article, we have discussed what causes the error and we have discussed ways to fix the error.
we hope this article has been informative. Thank you for reading. Kindly comment and let us know if you found it helpful.