简体   繁体   中英

VSCode: Using the MS Python extension cannot execute code

I have been using VSCode 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 VSCode, I have tried installing code runner. None of these have fixed the issue.

This is the image of my VSCode, which may help to solve the issue: 这是我的 VSCode 的图像,它可能有助于解决问题。

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

I have never experienced an issue like this before so any help is greatly appreciated. Thank you!

Image of the plugin I have installed.

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: 单击它以查看它的外观

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.

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

Do the following to remove stale versions of the extension:

1.Uninstall Python extension (if you have pylance uninstall it first) in visual studio code.

2.Close all instances of VS Code or close visual studio code.

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

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

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

6.Start VS Code, and install Python extension again(also pylance if you uninstalled it in step 1).

I figured it out!!! The most recent update for the Microsoft Python plugin on VSCode 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. Thank you all so much for the help!

Yep it's an issue with the most recent releases of vscode. 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 vscode 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. https://github.com/microsoft/vscode-python/issues/14959

Many others are facing the issue right now too. https://github.com/microsoft/vscode-python/issues/14977

I am using WSL2, and i encountered this error today. My VScode 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 WSL2, so i clicked on install and the problem was solved.

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

所以我遇到了这个问题并且找不到解决方案,直到我盯着 VS 代码并在左下角发现它处于受限模式,你必须在信任模式下运行它才能解决问题。

"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 vscode, it was successful.

Kindly install the Python interpreter from the following site: https://www.python.org/downloads/ Then vs code will ask for permission to run the interpreter. and then its done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM