用 where.exe 定位 Windows 中的可执行文件

列出命令名在 PATH 中的所有匹配——“到底运行的是哪个 python?”的最快答案。

Windows终端开发路径低风险
运行 `where.exe python`(PowerShell 里必须带 .exe 后缀),按执行优先级列出 PATH 上所有 python。

01命令

命令
$ where.exe python

02作用说明

where.exe 会依次搜索当前目录和每个 PATH 条目并打印所有匹配,第一行就是真正会被执行的那个。在 PowerShell 中 `where` 是 Where-Object 的别名,所以必须完整输入 where.exe——这是经典坑。它还能做简单的文件模式搜索(`where.exe /r C:\Projects *.sln`),但排查 PATH 问题时记住基本用法即可,配合 `$env:Path -split ';'` 可以看到原始搜索顺序。

03风险

风险低风险
使用条件Use `where.exe` explicitly in PowerShell — bare `where` runs Where-Object instead.

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • where | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    依据: Microsoft documents where.exe as displaying the location of files matching a search pattern, searching the current directory and PATH.
  • WHERE - Windows CMD
    SS64 · technical · 2026-09-17
    依据: SS64 explains where.exe searches PATH for executables and how it differs from PowerShell's Where-Object alias.

最后验证: 2026-09-17 · 分类: 开发者

06相关方案