ModuleNotFoundError: No module named 'requests' using venv in vscode
Question:
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'
.
- Using Visual Studio Code, installed today with standalone Python x64 3.7.4
- Python Extension installed in VSCODE
- 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
- ran
pip install requests
within terminal inside VSCODE – completed successfully
- ran
pip freeze
to confirm requests==2.22.0 is registered
- Verified pylint was installed in venv
I cannot figure out why VSCODE python interpreter will not recognize that requests is installed
Answers:
Is there more than one python environment locally?
maybe try:
pip3.7 install requests
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.
Have you checked your user and workspace settings?
Make sure your workspace settings (not your user settings) points to your project’s venv
path.
I have encountered a similar problem such as yours but was able to solve it by changing the workspace settings python path to point to my venv
path as below.
{
"python.pythonPath": "${workspaceFolder}/code/venv/bin/python"
}
2 ways work for me, under windows 10:
- Run in terminal: CTRL + F5
- Add the following in settings json:
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
}
Try using:
pip3 install requests
Python version was same in terminal & vs code
pip3 install requests
This works for me after installation error is gone
"import requests
ModuleNotFoundError: No module named ‘requests’ "
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'
.
- Using Visual Studio Code, installed today with standalone Python x64 3.7.4
- Python Extension installed in VSCODE
- 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
- ran
pip install requests
within terminal inside VSCODE – completed successfully - ran
pip freeze
to confirm requests==2.22.0 is registered - Verified pylint was installed in venv
I cannot figure out why VSCODE python interpreter will not recognize that requests is installed
Is there more than one python environment locally?
maybe try:
pip3.7 install requests
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.
Have you checked your user and workspace settings?
Make sure your workspace settings (not your user settings) points to your project’s venv
path.
I have encountered a similar problem such as yours but was able to solve it by changing the workspace settings python path to point to my venv
path as below.
{
"python.pythonPath": "${workspaceFolder}/code/venv/bin/python"
}
2 ways work for me, under windows 10:
- Run in terminal: CTRL + F5
- Add the following in settings json:
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
}
Try using:
pip3 install requests
Python version was same in terminal & vs code
pip3 install requests
This works for me after installation error is gone
"import requests
ModuleNotFoundError: No module named ‘requests’ "