我刚刚在 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.python
和 tht13.python
和 formulahendry.code-runner
VS代码上的扩展。
这是我的 main.py
代码:
print("Goodbye, World!")
原文由 Bizhan 发布,翻译遵循 CC BY-SA 4.0 许可协议
It turned out that I just had to restart my computer after I installed
ms-python.python
andtht13.python
andformulahendry.code-runner
extensions on the VS Code and added python’sScripts
文件夹在PATH
。Now both
py
andpython
commands work from anywhere likecmd
orRun Code
in the right click menu.