命令“where python”在 PowerShell 中不返回任何内容

Tar*_*iah 6 python powershell

正如标题所暗示的,当我尝试where python 从 PowerShell 中执行操作时,它什么也没有返回。没有错误或其他什么...它只是转到一个新行(就像我按“Enter”键一样)

另一方面,CMD Prompt 成功返回以下内容:

C:\Users\User>where python
C:\Users\User\AppData\Local\Programs\Python\Python38\python.exe
C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe
Run Code Online (Sandbox Code Playgroud)

python --version成功返回 pwsh 和 cmd中的版本。有人能弄清楚如何where在 powershell 中修复吗?

Mat*_*sen 18

在 PowerShell 中,where是 cmdlet 的别名Where-Object

要显式调用where.exe,请包含.exe扩展名:

PS ~> where.exe python
C:\Users\mathias\AppData\Local\Microsoft\WindowsApps\python.exe
Run Code Online (Sandbox Code Playgroud)

如果您想弄清楚为什么某个命令名称没有按预期解析,请使用Get-Command

PS ~> Get-Command where

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           where -> Where-Object


PS ~> Get-Command where*

CommandType Name                  Version      Source
----------- ----                  -------      ------
Alias       where -> Where-Object
Cmdlet      Where-Object          3.0.0.0      Microsoft.PowerShell.Core
Application where.exe             10.0.19041.1 C:\WINDOWS\system32\where.exe
Run Code Online (Sandbox Code Playgroud)

作为一个有趣的奖励,您新发现的知识Get-Command可能会被证明where.exe是过时的 - 显然Get-Command也有能力定位可执行文件:)

PS ~> Get-Command python
    
CommandType Name       Version Source
----------- ----       ------- ------
Application python.exe 0.0.0.0 C:\Users\mail\AppData\Local\Microsoft\WindowsApps\python.exe
Run Code Online (Sandbox Code Playgroud)