Troubleshooting "ImportError: No module named requests" in VS Code

Feb 3, 2024 ยท 2 min read

It can be frustrating when you try to import a Python library like requests in your VS Code project, only to run into an ImportError saying that VS Code can't find the module.

This usually happens because the library is not installed in the Python environment that VS Code is using. Here are some things you can try to resolve it:

Check your Python interpreter

First, check that you have selected the correct Python interpreter in VS Code. The path to the interpreter is displayed in the bottom left. Make sure it matches the Python installation where you installed requests.

If not, you can change it by clicking on the version and selecting another installed Python interpreter that has the requests module.

Reinstall requests

If the interpreter looks correct, try reinstalling requests:

pip install requests

This will install or reinstall requests for that Python environment.

Use a virtual environment

Another good practice is to create a virtual environment for your VS Code project. This creates an isolated Python environment just for that project's dependencies.

To set this up:

  1. Create a virtual env using python -m venv .venv
  2. Select the virtual env as the Python interpreter in VS Code
  3. Install requests with pip install requests

Now VS Code will use that local environment with requests available.

Restart VS Code

After changing any of these settings, you may need to close and reopen VS Code for the changes to fully take effect.

With the right interpreter configured and requests installed, the import issues should be resolved! Let me know if any other problems come up.

Browse by tags:

Browse by language:

Tired of getting blocked while scraping the web?

ProxiesAPI handles headless browsers and rotates proxies for you.
Get access to 1,000 free API credits, no credit card required!