The "ModuleNotFoundError: No module named 'requests'" error is a common issue in Python, indicating that the Python interpreter is unable to find the `requests` module. This module is a popular library used for making HTTP requests in Python. To fix this error, you need to ensure that the `requests` module is properly installed in your Python environment. Here's a step-by-step guide on how to resolve this issue:
Installing the Requests Module

The most straightforward way to install the requests
module is by using pip, Python’s package manager. You can install it via the command line or terminal. Open your command line or terminal and type the following command:
pip install requests
If you have multiple versions of Python installed on your system, you might need to specify the version of pip you want to use. For example, if you want to install the `requests` module for Python 3, you can use:
python3 -m pip install requests
Or, if you're using a virtual environment, ensure it's activated before running the installation command.
Resolving Installation Issues
If you encounter issues during the installation, such as permission errors, you can try using the --user
flag to install the module in the user directory:
pip install --user requests
Alternatively, you can use a virtual environment, which is a best practice for managing Python projects and their dependencies. To create a virtual environment, navigate to your project directory and run:
python -m venv myenv
Then, activate the virtual environment:
# On Windows
myenv\Scripts\activate
# On Unix or MacOS
source myenv/bin/activate
Once the virtual environment is activated, you can install the `requests` module using pip, and it will be isolated to this environment.
Verifying the Installation

After installing the requests
module, you can verify that it’s working correctly by running a simple Python script. Open a Python interpreter or create a new Python file (e.g., test_requests.py
) and add the following code:
import requests
response = requests.get('https://www.example.com')
print(response.status_code)
Run this script. If the `requests` module is installed correctly, you should see the HTTP status code of the request (typically 200 for a successful request). If you still encounter the `ModuleNotFoundError`, ensure that the Python interpreter you're using to run the script is the same one where you installed the `requests` module.
Troubleshooting Further Issues
If you continue to experience issues, consider checking the following:
- Python Version Compatibility: Ensure that the `requests` module is compatible with your Python version. You can check the compatibility on the official `requests` library documentation.
- Package Manager Issues: Sometimes, pip itself might need an update. You can update pip using `python -m pip install --upgrade pip`.
- Virtual Environment Mismanagement: If you're using a virtual environment, make sure it's activated when installing packages and running scripts.
- System-wide Package Installation: If you're installing packages system-wide (without a virtual environment), you might need to use `sudo` on Unix-like systems, but be cautious with this approach as it can lead to package management issues.
Troubleshooting Step | Description |
---|---|
Check Python Version | Verify that your Python version is compatible with the requests module. |
Update pip | Upgrade pip to the latest version to ensure you have the latest package installation capabilities. |
Use Virtual Environments | Isolate project dependencies by using virtual environments to avoid system-wide package conflicts. |
System-wide Installation | Use with caution; installing packages system-wide can lead to version conflicts and management issues. |

Key Points
- Install the requests module using pip.
- Verify that the Python interpreter used for installation matches the one used for running scripts.
- Consider using virtual environments for project dependency management.
- Check for Python version compatibility with the requests module.
- Update pip to the latest version for enhanced package management capabilities.
How do I know if the requests module is installed correctly?
+You can verify the installation by running a simple Python script that imports the requests module and makes an HTTP request. If the script runs without errors and returns the expected response, the module is installed correctly.
Why should I use virtual environments for Python projects?
+Virtual environments help isolate project dependencies, ensuring that packages installed for one project do not conflict with packages in another project or the system-wide Python environment. This makes managing dependencies and reproducing environments much easier.
By following these steps and considering the troubleshooting tips, you should be able to resolve the ModuleNotFoundError: No module named 'requests'
error and successfully use the requests
module in your Python projects.