无法在powershell上运行python

Alb*_*nci 0 python windows powershell

当我在 PowerShell 中输入 python 时,出现如下错误:

Program 'python' failed to execute: The system cannot find the file specified
At line:1 char:11
+ python.exe <<<< .
At line:1 char:1
+  <<<< python.exe
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed
Run Code Online (Sandbox Code Playgroud)

我已将 C:\Python27 及其子目录添加到 PATH。我可以通过键入 python.exe 来运行它。可以以相同的方式运行脚本。

我安装了 Python 2.7.11 64 位。

Gav*_*vin 7

我可以重现您的错误的唯一方法是将我的 python.exe 文件替换为名为 python.exe 的新空文本文件。

第一步

我注意到你提到你添加C:\Python27所有的子目录到PATH。我首先建议从您的路径中删除所有子目录(仅保留父目录)。确保在进行此更改后重新启动 Powershell 以引入新值。然后对其进行测试以查看这是否已解决问题。

替代方案

另一种可能性是您路径上的某个地方有损坏的 python.exe 或其他一些 cmdlet、函数或脚本文件,它们影响了您的 Python 安装。您可以尝试从 powershell 中运行:

Get-Command python | Select-Object -ExpandProperty Definition
Run Code Online (Sandbox Code Playgroud)

查看 powershell 实际引用的内容。*如果返回的唯一值是C:\Python27\python.exe那么我可能会建议重新安装。

笔记:

[*] -取自/sf/answers/1186438921/

  • 就我而言,“%AppData%\Local\Microsoft\WindowsApps\python.exe”处有一个 0KB 文件,该文件覆盖了我的标准 python 3.9 exe。 (2认同)