J930911
J930911

Reputation: 571

"Invalid python interpreter selected" prompt in VSCode

I've been trying to setup my Python workspace on Visual Studio Code but the software doesn't seem to pick up the fact that I have Python installed, and keeps telling me to install Python. I've tried manually adding the path of the .exe file but the "invalid interpreter prompt" shows up every single time. Just to proof I'm having the correct path in the settings here's a screenshot of the settings.json file:

screenshot of the settings.json file

and the command prompts I used to obtain the path:

screenshot of the command prompts

NB: I tried reinstalling both VSCode and Python through the instructions from the command palette, and ran VSCode as administrator but nothing made a difference. I added the python.exe file location to PATH as well.

Upvotes: 30

Views: 55055

Answers (12)

adamt8
adamt8

Reputation: 357

On windows, I tried downgrading the extension, 'run as administrator', and also updating the path with C:\Program Files\python39.

Here's what worked. I copied the C:\Program Files\python39 folder to C:\temp\python39. Then I selected C:\temp\python39\python.exe as the interpreter. This worked immediately.

Upvotes: 0

JustBeingHelpful
JustBeingHelpful

Reputation: 18980

Assuming Visual Studio Code previously worked and then you wake up one morning, it doesn't, the simplest explanation for this error is when Windows operating system does an automatic restart after X hours or X days, and Visual Studio Code opens up automatically on its own because it was previously open before the restart. Windows is not smart enough to open Visual Studio Code "as an Administrator".

To resolve this error, simply close Visual Studio Code and reopen "as an Administrator".

Note: My observation skills were tip top shape today and finally figured out "how the rabbit got in the fenced in garden" problem based on the movie Phenomenon. I can't even count how many times this happens to me.

Upvotes: 2

amirh_far
amirh_far

Reputation: 81

What solved my problem was:

It seemed that the autopep8 formatter was the main reason but I did all of this steps:
  • !! deleted the autopep8 extention & the configs related in the workspace-settings.json & in the user-settings.json
  • deleted the venv
  • deleted the python.defaultInterpreter setting in workspace-settings.json
  • deleted the python extention

after deleting these things, I installed:

  • python extention

  • recreated the venv

  • reloaded the window and selected the venv/bin/python in select interpreter command in the pallete

  • optional: installed autopep8 & configured it in the workspace-settings.json like this:

      "settings": {
          "[python]": {
              "editor.defaultFormatter": "ms-python.autopep8"
          }
    

Upvotes: 1

erdoganb
erdoganb

Reputation: 65

I've solved by, re-creating the environment with no spaces or underlines (_) in the folder name.

Upvotes: 1

Mayank
Mayank

Reputation: 51

Remove any blank spaces in your folder path. For me, this solved the problem.

Upvotes: 3

scriptDaddy
scriptDaddy

Reputation: 182

Re-Create the virtual venv solved it

Upvotes: 3

W Monsma
W Monsma

Reputation: 1

what fixed it for me was going to settings -> search "inherit env" and disable it.

(macos)

Upvotes: 0

Neo Machaba
Neo Machaba

Reputation: 11

Running VS Code as administrator helped with solving the invalid python interpreter problem.

Upvotes: 1

Wesley Cheek
Wesley Cheek

Reputation: 1696

For me, after investigating the problem in this issue, I found that the problem had to do with my ComSpec environment variable. This environment variable needs to be set to C:\Windows\system32\cmd.exe for the python extension to work.

Make sure to restart after changing the environment variable for changes to take effect

Upvotes: 3

Mark
Mark

Reputation: 1983

I tried all the suggestions above, none worked. I even tried reinstalling it, no luck.

What worked was downgrading to the previous version (in my case v2022.12.1) of the Python vscode extension then upgrading to the latest (which was v2022.12.1).

Upvotes: 1

Pascalco
Pascalco

Reputation: 2826

On my device (VSCode 1.71.2, Python extension 2022.14.0) I could solve the problem by clearing the python interpreter setting.

For this, use Ctrl+Shift+P to open the command palette. Then, enter Python: Clear Workspace Interpreter Setting. On the next panel, select to delete all.

After this, you should be able to select an interpreter by entering Python:Select Interpreter in the command palette.

Upvotes: 42

JialeDu
JialeDu

Reputation: 9727

First, make sure you have the python extension installed.

Then follow the steps below to choose an interpreter for vscode:

  1. Use Ctrl+Shift+P to open the command palette

  2. search for Python:Select Interpreter (or click select interpreter in the lower right corner)

    enter image description here

  3. If the panel shows an interpreter, select the available interpreter. If the panel doesn't have an interpreter option. Please select the first item Enter interpreter path

    enter image description here

  4. Then paste the full path to your python.exe (or go to explorer by selecting Find and select your python.exe)

    enter image description here

If it still fails, try installing the pre-release python extension.

enter image description here

Upvotes: 6

Related Questions