Xander Borgeson
Xander Borgeson

Reputation: 71

Visual Studio Code: Using the Microsoft Python extension cannot execute code

I have been using Visual Studio Code with the Microsoft Python extension for a couple of months now. However, just today I found that the green button I had in the top right that executed my code is gone. I have tried uninstalling the Python extension and reinstalling, I have deleted and redownloaded Visual Studio Code, I have tried installing code runner. None of these have fixed the issue.

This is the image of my Visual Studio Code, which may help to solve the issue:

This is the image of my Visual Studio Code, which may help to solve the issue.

When I tried to select the Python: select interpreter I got an error in the bottom right that says,

"Command 'Python: Select Interpreter' resulted in an error (command 'python.setInterpreter' not found)"

Image of the plugin I have installed.

Upvotes: 7

Views: 17170

Answers (10)

sandeepsinghnegi
sandeepsinghnegi

Reputation: 292

Reloading or upgrading the Python extension worked for me.

Upvotes: 0

user19784158
user19784158

Reputation: 1

Command 'Python: Select Interpreter' resulted in an error (command 'python.setInterpreter' not found)

The error happened on the newer version 3.10.6 I installed on my new system.

I uninstalled the new Python version. Then went to Microsoft store and installed the older version 3.9 directly from the store. When I tried adding the interpreter again on Visual Studio Code, it was successful.

Upvotes: 0

Mayur Kedare
Mayur Kedare

Reputation: 131

So I had faced the problem and couldn't find solution until I stared at Visual Studio Code and found at the bottom left corner that it was in restricted mode. You have to run it in trust mode and it will fix the problem.

Upvotes: 13

shaila
shaila

Reputation: 335

Try the following. If that does not help, create a new bug.

Do the following to remove stale versions of the extension:

  1. Uninstall the Python extension (if you have Pylance, uninstall it first) in Visual Studio Code.

2.Close all instances of Visual Studio Code or close Visual Studio Code .

  1. Go to, %USERPROFILE%/.vscode/extensions (on Windows) or ~/.vscode/extensions on Windows/Linux/Mac.

  2. Go to Run and give %USERPROFILE%/.vscode/extensions (on Windows). It will open extensions folder.

  3. Delete any folder with the name starting with ms-python.python*

  4. Start Visual Studio Code, and install the Python extension again (also Pylance if you uninstalled it in step 1).

Upvotes: 8

gmaz_tauruz
gmaz_tauruz

Reputation: 47

I am using WSL 2, and I encountered this error today. My Visual Studio Code used to work fine until my version was automatically upgraded to 1.60. When I checked my extensions, it said that my Python extension is not installed in WSL 2, so I clicked on install and the problem was solved.

Upvotes: 0

Min Htoo Lin
Min Htoo Lin

Reputation: 1

Yep, it's an issue with the most recent releases of Visual Studio Code. The quick fix right now is just to roll back to an older version. You can easily do this by pressing CTRL + Shift + X in Visual Studio Code to get to the extensions menu, and then clicking the Python extension, and then clicking the little arrow to the right of "uninstall". Here, you can just click "Install Another Version".

For me v2020.10.332292344 did the trick. command 'python.setInterpreter' not found #14959

Many others are facing the issue right now too. Gets stuck at "Python extension loading" then extension host crashes when telemetry.enableTelemetry is set to false #14977

Upvotes: 0

Xander Borgeson
Xander Borgeson

Reputation: 71

I figured it out!!! The most recent update for the Microsoft Python plugin on Visual Studio Code seems to be bugged or something; I'm not sure.

However, I installed an older version and everything works now, including bringing back the green run button.

Upvotes: 0

user14436708
user14436708

Reputation:

If the option is not coming, there is an option to run the program on the left panel in vs code which looks something like this:

Click on it to see how it looks properly

Then you need to click debug and run or whatever the option is, if that is blurred out then you've not saved the file, first save it and then again do the same options, and then it will run.

Upvotes: 2

Siddharth Parihar
Siddharth Parihar

Reputation: 1

Kindly install the Python interpreter from the following site: https://www.python.org/downloads/

Then Visual Studio Code will ask for permission to run the interpreter. And then it’s done.

Upvotes: -1

SuperTardigrade
SuperTardigrade

Reputation: 105

It may also come from the restricted mode. Please make sure you're in a trusted window.

Upvotes: 0

Related Questions