首页 > 解决方案 > 命令“where 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

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

标签: pythonpowershell

解决方案


在 PowerShell 中,whereWhere-Objectcmdlet 的别名。

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

PS ~> where.exe python
C:\Users\mathias\AppData\Local\Microsoft\WindowsApps\python.exe

如果您想弄清楚为什么某个命令名称没有按预期解析,请使用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

作为一个有趣的奖励,您新发现的知识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

推荐阅读