1

When implementing a Visual Studio extension to be used with Python files in the VSCode editor, how can one programmatically get the path of currently selected Python environment?

My guess is that it is done with python.pythonPath, but I can't seem to make it work. If I use that directly within an extension js, it crashes. I also tried:

let python = vscode.extensions.getExtension('python');
python.pythonPath

1 Answer 1

1

python.pythonPath is a setting, so you can do this with VSCode's generic settings API (instead of having to rely on the Python extension exposing an API specifically for this):

vscode.workspace.getConfiguration("python").get("pythonPath")
Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks, that was exactly what I was looking for. Didn't know I had to get the configuration and then get the variable, separately.

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.