Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I import requests in VS Code?

I want to use request module, but whenever I tried to import requests I got this message:

import "requests" could not be resolved from source Pylance

I already used pip to install the requests module, but I still receive this error message.

like image 593
Betty Gandhi Avatar asked Aug 18 '21 12:08

Betty Gandhi


People also ask

How do I fix the import error in VS code?

To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.

How do I fix an Importerror No module named Request?

Requests are not a built-in module (it doesn't come with the default python installation) in Python, you need to install it explicitly using the pip installer and then use it. If you are getting an error installing pip checkout pip: command not found to resolve the issue.


4 Answers

Have you made sure that you have installed the module by running

pip install requests

or

pip3 install requests

Additionally, you can tell VS Code to use different Python-interpreter in your system. I e.g. had the same problem, that VS Code code check gave me the warning, that I don't have the module requests installed, but when I run the python script it worked anyhow. That's why I believe that the python code check in VS Code can use different Python versions and related python packages than your system use when you run the code.

What helped me in order to get rid of the VS Code error message, choosing a different Python from here:

Screenshot of VS Code IDE. Change Python version for code check

like image 52
Anthony Avatar answered Oct 22 '22 14:10

Anthony


Try choosing the python interpreter manually. Choose view - select interpreter - enter interpreter path - choose the python folder - app then python application. This should work

like image 23
sumaiya thani Avatar answered Oct 22 '22 14:10

sumaiya thani


I got the same error and solved it with this:

import pip._vendor.requests 
like image 5
Murat Büyükaksu Avatar answered Oct 22 '22 12:10

Murat Büyükaksu


If you are experiencing this problem on Windows, look at the installed extensions. I had this problem on both of my Windows machines. I noted that I had two extensions installed: Pylance & Intellisense (Pylance). Uninstalling Pylance and keeping intellisense (Pylance) solved the problem.

like image 3
Chris Davies Avatar answered Oct 22 '22 13:10

Chris Davies