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 whereAlias where -> Where-Object即可继续操作。 - 临时删除当前会话的别名(仅对当前打开的PowerShell窗口生效,关闭后自动恢复):
Remove-Alias where -Scope CurrentUser - 永久删除别名:
执行命令打开PowerShell配置文件:
在打开的文本末尾加入以下内容,保存后重启PowerShell即可:notepad $PROFILEif (Test-Path Alias:where) { Remove-Alias where }
方案3:使用PowerShell原生等价命令
如果不想修改别名配置,也可以用PowerShell自带的Get-Command实现相同的查找效果:
Get-Command python -All
内容的提问来源于stack exchange,提问作者Taraxiah
相关产品推荐
相关产品推荐

