python - 命令 "where python"在 PowerShell 中不返回任何内容

标签 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 中的版本。有人能想出如何修复 powershell 中的 where 吗?

最佳答案

在 PowerShell 中,whereWhere-Object cmdlet 的别名。

要显式调用 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

关于python - 命令 "where python"在 PowerShell 中不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67693360/

相关文章:

用于希腊语单词的 Python 正则表达式

powershell - 使用 PowerShell 替换文本文件的内容

python - 当基于补丁的工作流程失败导致您的存储库中出现 .rej block 时,是否有任何补丁工具可以与 Mercurial 配合良好

python - Pandas 重新索引多索引无法正常工作

Azure 自动化 Powersell Runbook 失败 : 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet

xml - 如何使用Powershell从xml过滤以获取启动持续时间?

powershell - 从外部 URI 获取 JSON 对象中的值

c# - 在 Web 应用程序中通过 C# 调用 Powershell - 应用程序池标识问题

python 多线程用于继续循环直到用户输入。帮助理解所要求的示例

python - Django 和 python-docx