20

I've been trying to setup my python workspace on vscode 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 for proof of me having the correct path in the settings here's a screenshot of the .json file and the command prompts I used to obtain the path.

J930911
  • 371
  • 2
  • 3
  • 6
  • Maybe try restarting VS Code (from the command palette) or your computer? Also, VS Code might not have permissions to access/run that executable, so make sure to run it as an administrator. – abnathan Aug 06 '22 at 22:26
  • 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 – J930911 Aug 07 '22 at 09:54
  • 2
    I'm having the same problem here after I upgraded my python to 3.10.6 (LATEST at the time of writing). VS Code is reporting `An Invalid Python interpreter is selected, please try changing it to enable features such as IntelliSense, linting, and debugging.` and not accepting any virtual envs created with this version of python. – Wesley Cheek Aug 08 '22 at 00:57
  • Same for me, I even tried installing older (3.9/3.8) python versions and it still comes up with the same message. I'm wondering if the extension is running some python code (eg to get version etc) and getting an unexpected response?. – Giles Aug 09 '22 at 12:44
  • Is there any progress on the issue? – JialeDu Aug 10 '22 at 08:15
  • I ended up downgrading the VS Code Python extension to v10.1 (from v12.0) and it seems to have fixed the problem with the warning popup, but when I try to use Jupyter it's still telling me that python is not installed.. – Wesley Cheek Aug 17 '22 at 02:20

8 Answers8

24

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.

Pascalco
  • 2,481
  • 2
  • 15
  • 31
  • this solved my problem, but I still don't understand why... could you provide further explanation of what happened under the hood? At first, I thought I was having problems with PATH, but now I am even more confused. – Álvaro A. Gutiérrez-Vargas Oct 17 '22 at 18:07
  • 1
    On newer versions of VSCode, this is now called "Python: Clear Cache and Reload Windows" – jraufeisen Mar 15 '23 at 21:40
3

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

JialeDu
  • 6,021
  • 2
  • 5
  • 24
  • 5
    Tried all of this, including the pre-release version of the python extension. Still no luck. – Wesley Cheek Aug 17 '22 at 00:23
  • 1
    i did exactly these steps this morning and it worked for me. it found the three different python executables in my path. not sure if i restarted vscode after. i think so - after all, it is a microsoft product. – keithpjolley Aug 18 '22 at 01:57
3

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

DanGlen
  • 3
  • 1
Wesley Cheek
  • 1,058
  • 12
  • 22
0

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).

Mark
  • 1,337
  • 23
  • 34
0

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

0

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

(macos)

0

Re-Create the virtual venv solved it

scriptDaddy
  • 142
  • 1
  • 8
0

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

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Mayank
  • 11
  • 2