Reputation: 571
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:
and the command prompts I used to obtain the path:
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
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
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
Reputation: 81
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
Reputation: 65
I've solved by, re-creating the environment with no spaces or underlines (_) in the folder name.
Upvotes: 1
Reputation: 51
Remove any blank spaces in your folder path. For me, this solved the problem.
Upvotes: 3
Reputation: 1
what fixed it for me was going to settings -> search "inherit env" and disable it.
(macos)
Upvotes: 0
Reputation: 11
Running VS Code as administrator helped with solving the invalid python interpreter problem.
Upvotes: 1
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
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
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
Reputation: 9727
First, make sure you have the python extension installed.
Then follow the steps below to choose an interpreter for vscode:
Use Ctrl+Shift+P to open the command palette
search for Python:Select Interpreter
(or click select interpreter in the lower right corner)
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
Then paste the full path to your python.exe
(or go to explorer by selecting Find
and select your python.exe
)
If it still fails, try installing the pre-release python extension.
Upvotes: 6