VSCode:术语"python"无法识别...但是py可以工作 [英] VSCode: The term 'python' is not recognized...but py works
问题描述
我刚刚在VS Code上安装了python,并且无法使用 python
命令运行任何python代码.
python命令:
默认情况下,运行代码似乎运行 python
命令,并且无法识别.
当我右键单击并选择 Run Code
时,它会抱怨:
'python'不被识别为内部或外部命令,可操作程序或批处理文件
手动运行 python main.py
也是如此.
当我打开提升的PowerShell并运行 python
时,它会抱怨:
python:术语"python"未被识别为cmdlet,函数,脚本文件或可运行程序的名称.检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试.在第1行:char:1+蟒蛇+ ~~~~~~+ CategoryInfo:ObjectNotFound:(python:String)[],CommandNotFoundException+ FullyQualifiedErrorId:CommandNotFoundException
py命令:
它不会尝试使用 py
命令,但是会识别出它.当我手动调用 py main.py
时,它会起作用.
当我手动执行> py main.py
时,它会写下我的再见,世界!
问题:
如何仅通过使用CodeRunner的右键单击功能( Run Code
)使它在VS Code中编译/运行?
我已经在PATH中同时拥有Python文件夹及其Scripts文件夹.
我正在使用 VS Code 1.27.2
,并且已经在计算机上安装了 python 3.7.0
,并选中了用于自动添加环境变量的安装程序复选框.(路径没问题)
我还安装了VS Code上的 ms-python.python
和 tht13.python
和 formulahendry.code-runner
扩展./p>
这是我的 main.py
代码:
print(再见,世界!")
原来,安装 ms-python.python
后,我只需要重新启动计算机和VS Code上的 tht13.python
和 formulahendry.code-runner
扩展名,并在 PATH
中添加了python的 Scripts
文件夹
现在 py
和 python
命令都可以在右键菜单中的任何地方使用,例如 cmd
或 Run Code
I just installed python on VS Code and I can't run any python code using python
command.
python command:
Running the code seems to run python
command by default and it does not recognize it.
When I right click and choose Run Code
it complains:
'python' is not recognized as an internal or external command, operable program or batch file
Same goes for manually running python main.py
.
When I open an elevated PowerShell and run python
, it complains:
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 command:
It doesn't try to use py
command but it recognizes it. And when I manually call py main.py
, it works.
When I manually do >py main.py
it writes my Goodbye, World!
Question:
How can I make it compile/run in VS Code simply by using the CodeRunner's right-click feature (Run Code
)?
I already have both Python folder and its Scripts folder in PATH.
I'm using VS Code 1.27.2
and I have installed python 3.7.0
on my machine and have checked its installer checkbox for adding the environment variables automatically. (PATH is ok)
I also installed : ms-python.python
and tht13.python
and formulahendry.code-runner
extensions on the VS Code.
This is my main.py
code:
print("Goodbye, World!")
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
folder in PATH
.
Now both py
and python
commands work from anywhere like cmd
or Run Code
in the right click menu.
这篇关于VSCode:术语"python"无法识别...但是py可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!