VSCode:无法识别术语“python”......但 py 有效

新手上路,请多包涵

我刚刚在 VS Code 上安装了 python,我无法使用 python 命令运行任何 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

命令:

它不会尝试使用 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 并选中了它的安装程序复选框以自动添加环境变量。 (路径没问题)

我还安装了: ms-python.pythontht13.pythonformulahendry.code-runner VS代码上的扩展。


这是我的 main.py 代码:

 print("Goodbye, World!")

原文由 Bizhan 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
2 个回答

It turned out that I just had to restart my computer after I installed ms-python.python and tht13.python and formulahendry.code-runner extensions on the VS Code and added python’s Scripts 文件夹在 PATH

Now both py and python commands work from anywhere like cmd or Run Code in the right click menu.

原文由 Bizhan 发布,翻译遵循 CC BY-SA 4.0 许可协议

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

原文由 Hung Vu 发布,翻译遵循 CC BY-SA 4.0 许可协议

推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏