0

When I run the code below to attempt to import a few of the usual Python libraries for API interaction... I get a ModuleNotFoundError on the import line of code.

I verified that it is indeed installed on my machine via pip3. I then tried uninstalling it and reinstalling it. When that didn't work I tried running the installation as a shell command in my Jupyter notebook. The same errors persisted.

Please note: what I am referring to as "it" is either the requests or json library for Python; I am encountering the same errors with each.

#right on the import line is where the error happens, the code is simple though...

import requests
import json


Here is the traceback...

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-021831bd5cc5> in <module>
      1 # Dependencies
      2 get_ipython().system(' pip3 install requests')
----> 3 import requests
      4 import json

ModuleNotFoundError: No module named 'requests'

And here is the "requirement already satisfied" statement from Terminal...

(base) Computer:~ User$ pip3 install requests
Requirement already satisfied: requests in ./anaconda3/lib/python3.7/site-packages (2.22.0)
Requirement already satisfied: idna<2.9,>=2.5 in ./anaconda3/lib/python3.7/site-packages (from requests) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./anaconda3/lib/python3.7/site-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in ./anaconda3/lib/python3.7/site-packages (from requests) (2019.6.16)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./anaconda3/lib/python3.7/site-packages (from requests) (1.24.2)
mdecpm
  • 15
  • 1
  • 6
  • 1
    Can you show us the output of the command ```which python``` in the terminal as well as ```which python3```? – fendall Sep 09 '19 at 18:55
  • For ```which python``` the output is: ```/Users/username/anaconda3/bin/python``` For ```which python3``` the output is: ```/Users/username/anaconda3/bin/python3``` – mdecpm Sep 09 '19 at 18:59
  • How did you install "requests" module ? "pip3 install requests" or "sudo pip3 install requests" ? You should run "sudo pip3 install requests". – rprakash Sep 09 '19 at 19:01

2 Answers2

0

Sorry I’ve reputation to comment.

Pleas look at your env where you install the package. You’re running on base environment maybe you’re using Anaconda, and then run Python without that environment. So the package won’t be seen bye your editor or terminale. Could you add more information on where you use python?

abdoulsn
  • 842
  • 2
  • 16
  • 32
0

I was facing the same problem on mac OSX, when I did "pip install requests", then I installed with "sudo" and it worked.

On OSX/Linux :

Use $ sudo pip install requests if you have pip installed.

Alternatively you can also use sudo easy_install -U requests if you have easy_install installed.

For centOS: yum install python-requests

Reference: [ImportError: No module named requests

rprakash
  • 500
  • 5
  • 10