Why can’t I import requests in VS Code?

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

Leave a Comment