0

It worked...

Im on mac OS 10.15.7 and I have a function in a python script that needs the requests module. I followed the installation outlined here by user TheoretiCAL.

Last week I ran the script successfully from the VS code interpreter using python3.9.1.

...until it didn't:

Today I had to import requests in jupyter still in VS code. The module is not found despite VS being set to

  • python3.9.1 in the lower left corner
  • pip --version giving me:

pip 21.1.1 from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)

  • import sys print(sys.version) giving me 3.9.1
  • Also jupyter is running the right kernel as seen in the top right corner of VS (screenshot at the bottom of the page)

Unfortunately this did not help me any further either.

From my side it looks like I've done everything that is recommended. What did my tiny beginners brain miss?

enter image description here

enter image description here

Thank you for your help

ilam engl
  • 1,310
  • 1
  • 9
  • 22
  • Have you tried installing it with pip, just in case it hasn't downloaded properly? – SamTheProgrammer May 18 '21 at 16:35
  • I have installed it with pip. Or do you mean I should just do it again? – ilam engl May 18 '21 at 16:36
  • 1
    Try again in jupyter notebook, `!pip3 install requests` – KetZoomer May 18 '21 at 16:37
  • 1
    @ilamengl Try it again. And do what KetZoomer says. – SamTheProgrammer May 18 '21 at 16:38
  • @KetZoomer It did work! I don't understand why: I understand VS code uses whichever version of python I choose. When choosing said versions it should find the all installed modules within that version. -Correct. OR does it make a difference when running from the jupyter notebook??? – ilam engl May 18 '21 at 16:40
  • 1
    What you want to check is `sys.executable`. That's the python exe you're working with. – Diptangsu Goswami May 18 '21 at 16:45
  • @DiptangsuGoswami `'/usr/local/bin/python3'` - obviously I checked within the notebook :) – ilam engl May 18 '21 at 16:46
  • `$ /usr/local/bin/python3` `>>> import requests` does that work? – Diptangsu Goswami May 18 '21 at 16:48
  • @DiptangsuGoswami yes, just like it worked last week. It was only when importing within the notebook, when it did not work. – ilam engl May 18 '21 at 16:49
  • 1
    There are many things that are required before one can identify what the issue is. Are you using a virtualenv/conda env and launching jupyter from within it? How many versions of python do you have installed? How many of them have requests installed? vscode shows you what kernel it's using on the top right hand corner, is it what you want it to be? – Diptangsu Goswami May 18 '21 at 16:51
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232562/discussion-between-ilam-engl-and-diptangsu-goswami). – ilam engl May 18 '21 at 16:55
  • @ilamengl. Has your question been solved? – Molly Wang-MSFT May 19 '21 at 06:57

1 Answers1

2
  1. After selecting interpreter, you may install the module in current environment;

  2. Choose the same environment for Jupyter;

  3. Use pip show requests to check its location. If not in current selected environment, enter the environment and reinstall it.

enter image description here

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • 1
    All I wanna do is to solve your question and I'm glad to know it's already been resolved. so, it doesn't matter if you mark my answer now. Happy Coding. :) – Molly Wang-MSFT May 21 '21 at 02:49