I have a project in VSCode 1.86.2 on Windows 10 where it used to open terminals with venv automatically activated. Very handy.
It stopped working and I have not been able to turn this feature back on. There is no associated error message.
Setup
My pseudo path is like:
A pseudo path looks like:
C/
├─ Users/
├─ AlGrant/
│ ├─ test_pyrtlsdr/
│ │ ├─ .vscode/
│ │ │ ├─ settings.json
│ │ ├─ .venv/
│ │ │ ├─ Scripts/
│ │ │ │ ├─ python.exe
│ │ ├─ src/
Answers Searched
#1
I have tried to reactivate this feature by following this post which called for me to edit settings.json
in .vscode
directory and to add:
"python.terminal.activateEnvironment": true
or the second answer suggested:
"settings": {
"python.terminal.activateEnvInCurrentTerminal": true,
"python.defaultInterpreterPath": "~/venv/bin/python"
}
or even :
{
"python.terminal.activateEnvInCurrentTerminal": true,
"python.defaultInterpreterPath": "~/venv/bin/python"
}
Neither of those options worked. I presume on windows the path should be written : "/.venv/Scripts/python.exe" instead of bin? (which I tried)
#2
Another post here stated that the setting should be :
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
}
Again I also tried :
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/Scripts/python"
}
#3
And yet another post here suggested setting it vai the settings cog (bottom right):
And I added it like:
I note this settings file is located in the AppDataRoamingCodeUser folder (not project folder).
Does venv work
I have confirmed that I can manually activate the venv from command prompt – so thats not broken.
I note that the bottom right of VSCode suggests that it is using venv:
How can I have new terminals in VSCode activate the venv?
2
Answers
It appears this feature has been removed from the latest version of the VSCode Python plugin.
You can still check what evenv you are in by hovering over the terminal.
It has been raised as an issue here : https://github.com/microsoft/vscode-python/issues/22917
And Further information about how to check which venv your in is here : https://github.com/microsoft/vscode-python/wiki/Activate-Environments-in-Terminal-Using-Environment-Variables
I’ve been having the same issue and found that if you execute
which python
on your terminal window, you can validate which interpreter is being used (global or venv).It’s not as visual or friendly, but hope it helps.