Search code examples
pythonvisual-studio-codepython-requestsvirtual-environment

ModuleNotFoundError: No module named 'requests' using venv in vscode


I have 1 file, i get as far as line 1 import requests, nothing more yet and I receive the following error ModuleNotFoundError: No module named 'requests'.

  1. Using Visual Studio Code, installed today with standalone Python x64 3.7.4
  2. Python Extension installed in VSCODE
  3. venv created within VSCODE as a subfolder of workspace withint VSCODE terminal and was recognized by VSCODE when created and I am using venv interpreter in VSCODE as indicated on bottom bar
  4. ran pip install requests within terminal inside VSCODE - completed successfully
  5. ran pip freeze to confirm requests==2.22.0 is registered
  6. Verified pylint was installed in venv

I cannot figure out why VSCODE python interpreter will not recognize that requests is installed


Solution

  • Thanks for the responses. I found out my own issue after a few hours.

    First off I figured out somewhere that when I was running the terminal in VSCODE it was running against global interpreter. I then tried ./pip freeze and it worked as expected. This told me that the terminal was connected to the wrong interpreter.

    For some reason when I would 'run' the file it was executing in the terminal but it wasn't 'activating' the venv. I've closed and reopened VSCODE many times but for some reason when I closed the terminal window and reopened using CTRL+SHIFT+' and I received an error about signed scripts when it tried to activate my venv using the PS1 script. I ran Set-ExecutionPolicy -ExecutionPolicy RemoteSigned inside a normal PowerShell window and then reopened the Terminal window in VSCODE and it successfully activated my venv and I know see my venv name at the beginning of the line of the terminal. I then ran 'pip freeze' to confirm which modules installed inside of venv and then ran again in normal powershell window and it was different.

    There is documentation somewhere that says to run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned which I found later, but it would have been nice to know this was a requirement.