I am setting up vscode for python development. I have followed several youtube videos and have most everything working with python and virtual environments. I know virtual environments are properly detected by vscode because vscode automatically detects the 'venv' folder and displays this at the bottom left of my screen (Python 3.7.3 32-bit ('venv':venv)).

Ok, so the problem I have is when I right click on the python code and select "Run Python File in Terminal". What happens is a new terminal opens up and immediately runs the python script without first activating the virtual environment. I know this because there is no (venv) next to the new terminal prompt, even though there is always a (venv) there when I manually create new terminals.

I am using git bash as my default shell. I'm searching through my default settings.json file to see if there is a setting that makes sense, but I can't find anything.


OK, i figured it out. I used the following code to figure out which python executable it was using as it was running:

import sys


Turns out the terminal that is opened automatically is using the virtual environment but it doesn't give any indication such as (venv) while the script is running. And after the script ends, the virtual environment is immediately deactivated in the terminal it opened up. This is why it looked like it wasn't working. But when I printed out sys.executable it clearly was using the virtual environment python executable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.