Visual Studio Code run venv python

Viewed 1095

I created a venv in python. In CMD I can execute it with

Python\pyenv\Scripts\activate

and run my Scripts after that

python example.py

But how do I do it automatically in Visual Studio Code? If I press F5 or CTRL+F5 VSC tries to run another Python version but not my venv. In settings.json I have path to my venv:

{
"python.pythonPath": "Python\\pyver\\py391\\python.exe"
}

I need to write somewhere in my setting the Python\pyenv\Scripts\activate and execute it with python like Anaconda is doing it. I can see in my terminal if I press F5 with Anaconda it runs firstpath\to\Scripts\activate and after that it activade conda base and runs the python script. How do I set my setting like in Anaconda?

Thank you in advance :)

2 Answers

The python.pythonPath in your settings.json should be either absolute filepath or be prepended with ${workspaceFolder}:

"python.pythonPath": "${workspaceFolder}/Python/pyver/py391/python.exe"

The ${workspaceFolder} will be replaced with the path of the folder opened in VS Code.

Related