. Advertisement .
..3..
. Advertisement .
..4..
Your programming is running more smoothly than ever until it stumps you with the message: ModuleNotFoundError: No module named ‘requests’ in Python. What is it, and how should you fix it? Our guidelines below will give you some tips and examples.
Why Does The Error Occur?
Suppose you just learned about some amazing functionalities of Python’s requests library. You cannot wait to try them out! Hence, you start operating your codes with these statements!
Example 0:
import requests
Such a move is expected to transfer Pandas libraries into the (virtual) environment. However, to your dismay, the program only sends back ImportError: No Module Named Requests.
Example 0 (Error):
>>> import requests
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
One probable reason for the error is that Python does not offer “Requests” in its library. So installing that might solve your problem!
How to Fix The ModuleNotFoundError: No Module Named ‘Requests’ in Python?
Let’s look back at our <Example 0> above. As we have established, “Requests” might not be a functional feature in Python’s standard libraries. So you need to install “Requests” manually to make the program work!
Before the Pandas module’s importation, install it via Python’s manager “pip”. Ensure pip is 100% installed on the computer. Next, operate this command in the Windows shell:
Example 0 (Solution):
$ pip install requests
This command will install “Requests” in your macOS, Linux, or Windows virtual environments. The system should conclude that the “pip” has been updated on your computer. But what if it does not, you could use these two commands in the shell, command line, or terminal (it is safe to try out, after all):
Example 0 (Solution):
$ python -m pip install --upgrade pip
$ pip install pandas
Let’s look at another example. Suppose you wish to run the codes below:
Example 1:
import ree
Then instead of running those codes, the system sends you this message:
Example 1 (Error):
ModuleNotFoundError Traceback (most recent call last)
1 import ree
ModuleNotFoundError: No module named 'ree'
After installing "Pip." and "Requests" as how we instructed in <Example 0>, you may adopt "Pip" from the terminal:
Example 1 (Solution):
pip show requests
Example 1 (Solution):
Name: requests
Version: 2.25.1
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Anna Keith
Author-email: [email protected]
License: Apache 2.0
Location: /Users/Yusufu.Shehu/opt/anaconda3/lib/python3.8/site-packages
Requires: urllib3, chardet, idna, certifi
Required-by: tensorboard, Sphinx, requests-oauthlib, jupyterlab-server, conda, conda-repo-cli, conda-build, anaconda-project, anaconda-client
Next, within the Python programs, you may import requests before referencing the_version_attribute:
Example 1 (Solution):
import requests
print(requests.__version__)
Example 1 (Solution):
2.25.1
Conclusion
This article has shown you how to fix the ModuleNotFoundError: No module named ‘requests’ in Python. For similar ModuleNotFoundError issues (such as “No Module Named ‘tensorflow’“), feel free to browse through ITtutoria guidelines for more support.
Leave a comment