user13026362
user13026362

Reputation:

Python VS Code imports not working 'No module name requests'

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

Upvotes: 3

Views: 3801

Answers (1)

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.

Upvotes: 3

Related Questions