Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preselect (set default) python interpreter in python visual code extension?

The small problem is, when I press Ctrl+F5, I want the code to be run immediately; but I have to

Select environment:

Python
Python Exprimental

all the time. Is there a way to set default env in settings so I don't have to choose at each run?

like image 759
Emil Avatar asked Apr 13 '18 13:04

Emil


2 Answers

vscode deprecated the python.pythonPath setting.

Since the 2021.6.0 (16 June 2021) update we should use

Windows:

{
  "python.defaultInterpreterPath": "c:/dev/ala/venv/Scripts/python.exe"
}

macOS/Linux:

{
  "python.defaultInterpreterPath": "/home/abc/dev/ala/venv/bin/python"
}

The vscode documentation has already been updated. https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter

like image 62
krema Avatar answered Oct 22 '22 08:10

krema


Once you selected an interpreter, it should be stored in the settings.json file in .vscode folder. It should be something like this:

{
  "python.pythonPath": "C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python36\\python.exe"
}

Next time you use vscode to open this folder, the python interpreter you used last time should be automatically selected.

Maybe you didn't use "Open folder" to open the working directory. And then vscode will try to read the local .vscode folder if any, otherwise it will follow a certain path order to select an interpreter. Hope that helps.

like image 7
user1422543 Avatar answered Oct 22 '22 07:10

user1422543