35
votes

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?

7
So what's the error message and what you have done so far?zhiqiang huang

7 Answers

35
votes

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

13
votes

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

7
votes

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
votes

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.

0
votes

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
votes

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
votes

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.