How to pip install the requests module to solve import errors?

Couple days ago i installed a clean Python3.X environment using MiniConda. After launching Jupyter Lab and trying to start working with the requests module, i got an import error.

In this post i will show you how to easily troubleshoot requests import errors in your Python development environment of choice, being it Jupyter, PyCharm, Spyder etc’ and Python distribution.

Troubleshooting the no module named requests error

Using pip

If you are installing your Python packages manually, not using Anaconda / MiniConda or other prepackaged distribution, it’s easily to use the Python package management utility (PIP) to solve this issue. I’ll go through the fix process for a Windows computer, those will be pretty quite similar in macOS or Linux distributions.

To solve the modulenotfounderror no module named requests, proceed as following:

  1. First, go ahead and close your Python editor environment.
  2. Then open your command line ( Windows: Start >> run >> cmd) or Terminal.
  3. Now type the following command:
pip install requests
  1. Next, go ahead and close your command or Terminal window.
  2. Now go ahead and reopen your Python editor and import requests.
import requests as re

Using MiniConda

If you are using MiniConda then follow these steps:

  1. Close your Python editor.
  2. Hit the Windows icons and type Anaconda Prompt. and hit Enter.
  3. Then type: conda activate <your_environment_path> and hit Enter. As an example, you’ll type C:\envs\Python3.81
  4. Then type pip install requests and Enter.
  5. Re-open your Python Editor and keep coding.

No module named requests – even after i pip install

Issue: you are still getting the import error even after executing the installation using pip or the Anaconda Environment Manager.

Solution: ensure that you have indeed closed your Python editor before importing the package. If still you get and error, reboot your Windows PC and try again.

Warning / Errors when trying to pip install requests

Issue: When trying to import the requests module from the Python package repository, you encounter the following error:

ERROR: Could not find a version that satisfies the requirement requests (from versions: none)

Solution: most probably you have an issue with your Internet connection. Ensure that you are online and try again.