Reputation: 108
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'
.
pip install requests
within terminal inside VSCODE - completed successfullypip freeze
to confirm requests==2.22.0 is registeredI cannot figure out why VSCODE python interpreter will not recognize that requests is installed
Upvotes: 6
Views: 45896
Reputation: 81
2 ways work for me, under windows 10:
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
}
Upvotes: 1
Reputation: 89
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"
}
Upvotes: 5
Reputation: 631
try get python version in vscode terminal
python --version
and check python version vscode IDE used by clicking left buttom corner.
make sure these 2 versions are consistent. if not, select the version of IDE with the same version of your terminal.
Upvotes: 14
Reputation: 108
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.
Upvotes: 2
Reputation: 44
Is there more than one python environment locally? maybe try:
pip3.7 install requests
Upvotes: 1