VSCode:术语“ python”无法识别...但是py可以工作

Biz*_*han 6 python automation build visual-studio-code vscode-code-runner

我刚刚在VS Code上安装了python,但是我无法使用来运行任何python代码 python command。

python命令:

好像用了 python默认情况下命令,但无法识别命令。

当我右键单击并选择Run Code它时抱怨:

'python' is not recognized as an internal or external command, operable program or batch file

手动运行也是如此 python main.py

当我打开提升的PowerShell并运行时python,它抱怨:

python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

py命令:

它不会尝试使用py命令,但会识别它。当我手动打电话时py main.py,它可以工作

当我手动执行时,>py main.py它会写我的Goodbye, World!

题:

如何仅通过使用CodeRunner的右键单击功能(Run Code)在VS Code中进行编译/运行?


我已经在PATH中同时拥有Python文件夹及其Scripts文件夹。

我正在使用,VS Code 1.27.2并且已经安装python 3.7.0在计算机上,并选中了其安装程序复选框以自动添加环境变量。(路径正常)

我还在VS Code上安装了:ms-python.pythontht13.pythonformulahendry.code-runner扩展名。


这是我的main.py代码:

print("Goodbye, World!")
Run Code Online (Sandbox Code Playgroud)

Biz*_*han 9

原来,我不得不重新启动我的电脑安装后,我ms-python.pythontht13.pythonformulahendry.code-runner扩展的VS代码,增加了Python的Scripts文件夹中PATH

现在,pypython命令都可以在任何地方使用,例如右键菜单中cmdRun Code右键菜单中。

  • jaja 这就是解决方案,只需重新启动计算机 (2认同)

Hun*_* Vu 5

安装 Python 扩展并更改 PATH 以包含 Python 及其脚本文件夹后重新启动 PC 将会有所帮助。为我工作