37

In Windows 10, How Visual Studio Code should be configured to find the Python 3 interpreter?

Visual Studio Code is not able to find the Python 3 interpreter.

I have added the Python extension, the Python extension at https://marketplace.visualstudio.com/items?itemName=donjayamanne.python.

How settings.js should be changed to use Python?

Even if python.pythonPath in settings.js is changed to be led to python.exe, which is at "C:\Users<User>\AppData\Local\Programs\Python\Python36-32\p‌ython.exe", if I select Python: Select Workspace Interpreter in the command palette, I get the message Please open a workspace to select the Python Interpreter. Why is this happening?

1
  • So what's the error message and what you have done so far? Commented Apr 10, 2017 at 2:13

8 Answers 8

36

macOS

VSCode -> Preferences -> Settings -> scroll down to Python Configuration.

Click the pencil on the left of the configuration you'd like to use and click Copy Settings.

"python.pythonPath": "python3.6"

enter image description here

enter image description here

1
  • 1
    So the question asked for Windows but you answered for MacOS??
    – elkshadow5
    Commented May 28, 2020 at 15:22
15

Go to File/Preferences/Settings and find Python Configuration. This is where you manually change the configurations.

You can also select your interpreter from command palette. The following instructions are from DonJayamanne's Github.

Select the command Python: Select Workspace Interpreter from the command palette

Upon selecting the above command a list of discovered interpreters will be displayed in a quick pick list

Selecting an interpreter from this list will update the settings.json file automatically.

Command Pallet Screenshot

4
  • 1
    I edited settings.js and changed pythonPath and did use "Python: Select Workspace Interpreter" But still the message VS Code gives is 'no interpreter'. I don't know whether I am doing the editing right.Can you please show how to edit settings.js
    – Varuna
    Commented Apr 10, 2017 at 2:26
  • 15
    But what if the interpreter I want doesn't appear in that list?
    – seven-dev
    Commented Aug 6, 2019 at 13:20
  • 3
    @SadSeven Help (F1) > "Workspace Settings" > "python:venv" You should see: "Python: Venv Path Path to folder with a list of Virtual Environments (e.g. ~/.pyenv, ~/Envs, ~/.virtualenvs)." Add the absolute path to the list of your virtual environments here and you will be able to select it from that dropdown. This adds the "python.venvPath" to your .vscode/settings.json file.
    – DragonBobZ
    Commented Mar 12, 2020 at 15:39
  • It is possible to solve it like this now: View > Command Palette (F1) > Python: Select Interpreter > Enter interpreter path...
    – Sefan
    Commented Aug 3, 2021 at 11:55
7

In the current directory where you open you VS Code, go to .vscode/settings.json and modify this line in the json file:

 {
    "python.pythonPath": "path_to_your_python_bin", 
    # e.g., /home/myname/venv/bin/python3.7 or to a .exe file if you are on Windows
 }
4

I'm also using this Python extension in Visual Studio Code on Windows 10. Python is installed in C:\Python27\ and C:\Python36\ and both folders are added to the Windows PATH variable With this setting VS Code should be able to find the Python interpreter. At least in my environment it worked well.

But VS takes the first interpreter it can find, which was in my case the Version 3.6. When I need 2.7 for a project I have to tell VS Code explicitely to use that one in the configration file settings.json In VS Code press Ctrl, and then, in the right window add:

{
"python.pythonPath": "c:/python27/python.exe"
}

or whatever is the path to the Python interpreter on your PC.

This is also described in the Wiki under Manual Configuration. Now, with this setting Python 2.7 was used.

Something that did not work was that the automatic detection of the Python versions and therefore I could also not choose the version I need with the Select an Interpreter command.

3
  • 1
    Even if the python.pythonPath in settings.js is changed to the python.exe path, which is in windows 10 is "C:\Users\<User>\AppData\Local\Programs\Python\Python36-32\python.exe" VS code displays the message "Please open a workspace to select the Python Interpreter".
    – Varuna
    Commented Jul 29, 2017 at 2:24
  • code.visualstudio.com/docs/getstarted/settings - Workspace These settings are stored inside your workspace in a .vscode folder and only apply when the workspace is opened. Settings defined on this scope override the user scope.
    – Varuna
    Commented Jul 29, 2017 at 2:31
  • Add the path to the new interpreter in the environment path variable works for me. VS Code 1.32.3 (over Windows 10) managed to recognise the new python interpreter version.
    – framontb
    Commented Mar 20, 2019 at 9:05
2

The Please open a workspace to select the Python Interpreter. error is simple. I believe you've opened a VS Code window without selecting any folder. As such, no workspace was opened, and workspace-specific settings cannot be set.

If you wish to set a default python interpreter for all workspaces, open settings with Ctrl+Shift+P, Preferences: Open User Settings and search for Python: Default Interpreter Path. Otherwise, if you want to set it for only the current workspace, use Preferences: Open Workspace Settings.

VS code settings for default python interpreter

In your case, you wish to set it to C:\Users<User>\AppData\Local\Programs\Python\Python36-32\p‌ython.exe. Though I would suggest using a virtual environment. If you edit settings.json directly instead of using the GUI:

{  
  "python.defaultInterpreterPath": "C:\Users<User>\AppData\Local\Programs\Python\Python36-32\p‌ython.exe"
}  

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. Therefore most other answers are outdated:

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)

0

I also had this problem. I did what @jps said and it still didn't work, but then I changed my Environment Settings order so that Python36 precedes Python27, and it worked.

0

In my case I have seen the actual workspace you are working in override the File/Preferences/Settings (Windows) or Code/Preferences/Settings (Mac).

The solution was to manually edit the workspace file (usually in your home directory) or to create a new workspace and re-add your directory for your code.

0

Uninstall x64 version. and Install the x86 32bit version. Exclude python from AV. this should do the trick. The Python extension. Be Sure to restart the VSCode each time.

Your Answer

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

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