How to fix: No module named ‘requests’ in Python
In this tutorial, we will learn how to fix ModuleNotFoundError: No module named ‘requests’ in Python
When it occurs?
The Python error “ModuleNotFoundError: No module named ‘requests‘” occurs when the requests module isn’t installed before importing it, or it’s installed in an incorrect environment.
Solution
To fix this issue, you can use pip which is a Python default package manager, to install the ‘requests’ library. Follow these steps:
- First, make sure you have pip installed by running
pip --version
in your terminal. If it is not, delete and reinstall Python from the official website. - Open a terminal or command prompt.
- Enter the following command:
# For Windows pip install requests # For mac/linux pip3 install requests # Alternative for Ubuntu/Debian sudo apt-get install python3-requests # For Jupyter/Colab Notebook !pip install requests # If you do not have pip in your PATH environment variable python -m pip install requests # For python 3 python3 -m pip install requests
- After the installation completes, try to execute your code again and don’t forget to import the requests module by the command:
import requests
We’ve successfully covered how to resolve the “No module named ‘requests'” error in Python, simplifying the solution for better comprehension. I trust you found the process enjoyable and informative!
Leave a Reply