17

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?

2
  • 1
    user1422543's answer is correct. Visual Code remembers the settings for a project/workspace using the .vscode/settings.json file which is in the root folder of the project. Once it is set, every time you open that project, vscode will set the right environment Dec 13, 2019 at 12:51
  • Does this answer your question? In vscode using Python, ctrl+F5 always asks for "select environment"
    – Henke
    Jul 4, 2020 at 9:10

4 Answers 4

15

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

8

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.

1
4

File > Preferences > Settings > User tab > Extensions > python > Python Path

type your python path e.g.: c:\python35\python.exe

1
0

press ctrl+shift+p to launch command pallete and

type python interpreter and you will get an option select interpreter

then select python interpreter

Choosing an environment By default, the Python extension relies on the first Python interpreter it finds in the path, but it's easy to switch between environments.

To use a specific interpreter, select the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).

2
  • 1
    This does not help. I select the only one (python 2.7.14 64 bit interpreter), but when I press ctrl+f5 I get the choice between python and python experimental again.
    – Emil
    Apr 14, 2018 at 10:43
  • then press ctrl+, open the setting and search for python, you wil get the option for setting the python interpreter where u give the full path
    – Roushan
    Apr 14, 2018 at 13:54

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

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