Skip to content Skip to sidebar Skip to footer

VSCode Change Default Python Version

When I code on VSCode and don't specify a python version it is set to python2.7.17 I would like to set it by default to python3.6 I tried doing so by adding this at the top of my

Solution 1:

In VSCode's command palette choose the option

Python: Select Interpreter

And choose the interpreter you want to use. This will automatically add the setting correctly to your settings.json file in your .vscode folder for your workspace.

python list vscode

This will take care of Python management in VSCode.

Now coming to setting the right python to be used by your os/terminal when trying to run scripts.

Since you are using linux, make sure your python is the right version thats linked

  1. Check python version on terminal - python --version
  2. execute sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 << verfiy your paths correctly
  3. then run sudo update-alternatives --config python
  4. Select the python version
  5. Try python --version again and check

If on Windows make sure path to Python 3.8.x is set at a higher priority in your Path Environment Variable. Py3 should be above your other paths

Path for Python


Solution 2:

Open settings and search for Python Default Interpreter Path.

VS code settings for default python interpreter

In your case, you wish to set it to /usr/bin/python3.6. Though I would suggest using a virtual environment.

{  
  "python.defaultInterpreterPath": "/usr/bin/python3.6"
}  

If you are using virtual environment, to ensure that the terminal is using the associated python environment, check the second option Python > Terminal: Activate Environment:

Activate Python Environment in VS Code

In settings.json it is called "python.terminal.activateEnvironment": true.

One reason your change did not persist, was because in your screenshot, you opened your workspace's settings.json. To make it default, you should edit your user's settings.json instead. This you can access with Ctrl+Shift+P, Preferences: Open Settings (JSON). Detailed instructions can be found in the documentation "Manually specify an interpreter", including using environment variables as the interpreter's path.

Also, "python.pythonPath" has been deprecated:

2021.6.0 (16 June 2021)
5. Added python.defaultInterpreterPath setting at workspace level when in pythonDeprecatePythonPath experiment. (#16485)
8. Show python.pythonPath deprecation prompt when in pythonDeprecatePythonPath experiment. (#16485)

2020.7.0 (16 July 2020)
9. Prompt users that we have deleted pythonPath from their workspace settings when in Deprecate PythonPath experiment. (#12533)

2020.5.0 (12 May 2020)
6. Do a one-off transfer of existing values for python.pythonPath setting to new Interpreter storage if in DeprecatePythonPath experiment. (#11052)
8. Added prompt asking users to delete python.pythonPath key from their workspace settings when in Deprecate PythonPath experiment. (#11108)
12. Rename string ${config:python.pythonPath} which is used in launch.json to refer to interpreter path set in settings, to ${config:python.interpreterPath}. (#11446)

2020.4.0 (20 April 2020)
13. Added a user setting python.defaultInterpreterPath to set up the default interpreter path when in Deprecate PythonPath experiment. (#11021)


Post a Comment for "VSCode Change Default Python Version"