1

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 :)

3 Answers 3

0

You have to select the interpreter: https://code.visualstudio.com/docs/python/environments

Sign up to request clarification or add additional context in comments.

1 Comment

@Steinfeld. Also there's a default setting "python.terminal.activateEnvironment": true, which can activate the environment automatically when you open a new Terminal(Ctrl+Shift+`). So you don't have to activate it manually every time in the Terminal.
0

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.

Comments

0

By using the 'select Interpreter' from the settings, you get the choice of locally installed Python versions and the option to create a venv inside your workspace folder.

But I found you can also use a venv previously installed elsewhere.

To do this, go to 'select Interpreter', then choose "Enter Interpreter path". Here, select the python found in the venv. On Windows, this is [venv]\Scripts\python.exe , on Linux, this is the symlink [venv]/bin/python .

VS Code understands this and then uses that particular environment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.