You need to enable JavaScript to run this app. PowerShell执行where python无返回但CMD运行正常如何修复
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell执行where python无返回但CMD运行正常如何修复

问题原因

PowerShell中默认将where设置为内置cmdlet Where-Object的别名,和CMD里的where.exe工具不是同一个程序。你直接在PowerShell中执行where python相当于调用Where-Object python,没有匹配的管道输入自然不会返回任何结果,也不会触发报错。

解决方案

方案1:直接调用原始where.exe(临时使用,无需修改配置)

只要在PowerShell中输入完整的程序名加后缀即可得到和CMD完全一致的输出:

where.exe python

方案2:删除PowerShell的where别名(永久生效,后续输入where默认调用where.exe)

  • 首先确认当前where别名的指向:
    Get-Alias where
    
    正常返回结果为Alias where -> Where-Object即可继续操作。
  • 临时删除当前会话的别名(仅对当前打开的PowerShell窗口生效,关闭后自动恢复):
    Remove-Alias where -Scope CurrentUser
    
  • 永久删除别名:
    执行命令打开PowerShell配置文件:
    notepad $PROFILE
    
    在打开的文本末尾加入以下内容,保存后重启PowerShell即可:
    if (Test-Path Alias:where) { Remove-Alias where }
    

方案3:使用PowerShell原生等价命令

如果不想修改别名配置,也可以用PowerShell自带的Get-Command实现相同的查找效果:

Get-Command python -All

内容的提问来源于stack exchange,提问作者Taraxiah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.18 19:27:05