3

I'm new to python, coming from 6 months of c++ and am also new to VS Code (from VS).

My error is>

Exception has occurred: ModuleNotFoundError No module named 'requests' File "C:\Users\ryanb\Documents\Python\main.py", line 1, in

import requests

on anything which begins with :

import requests

this works fine in VS, but I have been encouraged to use Code. When I ran the pip command it said 'satisified'.

PS C:\Users\ryanb\Documents\Python> pip install requests
Requirement already satisfied: requests in c:\users\ryanb\anaconda3\lib\site-packages (2.22.0)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (3.0.4)
PS C:\Users\ryanb\Documents\Python>

I have anaconda, though I'm new to it as well, but I seem to get the problem either way. Initially my problem was that it wouldn't find the interpreter but this was resolved after I installed add on files to visual studio (not visual studio code) and used the interpreter which came with that.

Please advise.

Thank you

1 Answers1

3

You may have several python versions installed (e.g. 3.6 32-bit, 3.6 64-bit, 2.7, ...). I would recommend to "natively" install Python from https://www.python.org/ instead of using Anaconda. The problem can happen because VS code is using another Python, different than the one you installed requests. You can verify this if pip3 is installed: try pip3 --version. Anyway, you can change the interpreter VS code is using by clicking the lower bar: screenshot

Or you might just run pip3 install requests.

I would recommend you to leave just one Python installed in your machine.

  • Thank you, I have uninstalled anaconda and VS code and it seems to work now, although only when I choose certain interpreters (the anaconda one seems to work fine) from the command palette. I assume this is different installs? or environments? –  Mar 28 '20 at 03:26
  • They are different and independent python versions living in your computer. To avoid confusions and [problems](https://stackoverflow.com/questions/14117945/too-many-different-python-versions-on-my-system-and-causing-problems), try to minimize how many Pythons you have installed. – Ignacio F. Garcés Mar 29 '20 at 01:57