简体   繁体   English

vscode 的代码运行器无法正常运行 python

[英]Code runner for vscode can't run python without error

I've installed Python 3.10.5 on my Windows 10 machine.我已经在我的 Windows 10 机器上安装了 Python 3.10.5。 Works splendidly running a file by writing "python file.py".通过编写“python file.py”出色地运行文件。 What I can't do though, is to get the extension code runner to run python files through the hotkey ctrl + b.但是我不能做的是让扩展代码运行器通过热键 ctrl + b 运行 python 个文件。 I've reinstalled Python (made sure to check PATH).我已经重新安装了 Python(确保检查 PATH)。 Rebooted the computer and reinstalled code runner.重新启动计算机并重新安装代码运行程序。

If I change no settings I get this error:如果我不更改任何设置,我会收到此错误:

"/usr/bin/python3: The term '/usr/bin/python3' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again."

I found this similar thread: Code Runner does not work for Python in VsCode我发现了这个类似的线程: Code Runner does not work for Python in VsCode

After changing the code in settings.json to将 settings.json 中的代码更改为

"code-runner.executorMap": {
    "python": "\"$pythonPath\" $fullFileName",
}

I get the error:我收到错误:

1 | 1 | … Data\Local\Programs\Python\Python310\python.exe" "c:\lekspel\test.py" | ~~~~~~~~~~~~~~~~~~~~ | Unexpected token '"c:\lekspel\test.py"' in expression or statement. … Data\Local\Programs\Python\Python310\python.exe" "c:\lekspel\test.py" | ~~~~~~~~~~~~~~~~~~~~ | 意外的令牌 ' "c:\lekspel\test.py"' 在表达式或语句中。

adding in a "-u" returns this error:添加“-u”会返回此错误:

Unexpected token '-u' in expression or statement.表达式或语句中出现意外的标记“-u”。

Anyone got a clue how to sort this out?任何人都知道如何解决这个问题?

I solved it by doing a fresh install of vscode, deleting my settings in roaming.我通过全新安装 vscode 解决了这个问题,删除了我在漫游中的设置。 Not an optimal solution by any means, but got it out of the way at least.无论如何都不是最佳解决方案,但至少把它排除在外。

got the same error.得到了同样的错误。 it was because i added "py" to path during installation setup (check by typing "py" in terminal if it opens python) so coderunner wasn't able to run python with "python" keyword, anyway try the following solution and tell me if it works:这是因为我在安装设置期间向路径添加了“py”(如果它打开 python,请在终端中输入“py”进行检查)所以 coderunner 无法使用“python”关键字运行 python,无论如何请尝试以下解决方案并告诉我如果有效:

1.Go to extensions 1.Go 到扩展

2.Right click -> extension settings 2.右击->扩展设置

3.Edit settings in Json for any option settings of coderunner 3.在Json中编辑设置coderunner的任意选项设置

4.change "python -u" to "py -u" like this 4.像这样将“python -u”更改为“py -u”

5.save json file with crl+s. 5.用crl+s保存json文件。

Run code again再次运行代码

tell me if it works for you.告诉我它是否适合你。 here mine worked like this这里我的工作是这样的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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