【发布时间】:2020-06-22 00:22:18
【问题描述】:
我是编程新手。再试一次。
我已经能够通过更改环境变量使 Python 从 PowerShell 运行。当我尝试使用 Win + R 启动 Python 时,只有 py 启动 python。这让我很困惑。 PowerShell 和 cmd 只需键入 python 即可。
我也在努力做到这一点,以便我可以从任何地方启动一个 python 脚本。我在 Visual Studio 代码中创建了一个名为 again.py 的简单脚本,并将脚本保存在特定文件夹中。当我尝试在 VSC 中运行脚本时,我总是收到错误消息:
[Running] python -u "c:\Users\xyz\Programming\Python\again.py"
'python' is not recognized as an internal or external command,
operable program or batch file.
[Done] exited with code=1 in 0.137 seconds
据我了解,如果路径中包含一个文件夹,并且调用了存储在该文件夹中的文件,则该文件/脚本应该运行。我应该可以从任何地方调用该文件,但我无法在 PowerShell 或 Run 中键入文件名并运行它。
win + R 返回:
Windows cannot find 'again.py'. Make sure you type the name correctly, and try again.
PowerShell:重新开始.py
start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
+ start again.py
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
在 cmd 中再次键入 .py 会使其运行正常。
【问题讨论】:
-
你能在 VSC 中运行
python吗?你的实际路径是什么? -
对于 xyz 的用户变量,变量名称是
PYTHON_HOME变量值是C:\Users\xyz\AppData\Local\Programs\Python\Python38I还在系统变量中的Path中添加了;C:\Users\xyz\AppData\Local\Programs\Python\Python38。 -
以某种方式尝试使用终端启动 Python 是 VSC 失败。这就是我得到的:
PS C:\Users\xyz> Start Pythonstart : This command cannot be run due to the error: The system cannot find the file specified. At line:1 char:1 + start python etcVSC 不应该只能找到 Python 吗?我如何告诉 VSC 在哪里寻找 Python? -
哈哈。使用
start again.py时,这实际上会在 VSC 中启动代码。 shebang 甚至都无所谓。伙计,这是一个如此简单的程序。我很困惑为什么它不会运行。#! python msg = "Hello World" print = ("Hello World")
标签: python powershell path