error: "PowerShell.exe" shell is not among the supported options: "bash zsh fish sh ksh dash nu pwsh.exe pwsh powershell.exe powershell cmd.exe cmd"
18 2025-10-21 13:21
你这个问题已经不是简单的 shell 识别失败了,而是 ESP-IDF 的激活脚本在 PowerShell 环境下有 bug,尤其是 5.4.1 版本的
export.ps1
脚本在 Windows PowerShell 下存在兼容性问题。✅ 根本原因
-
ESP-IDF 的
export.ps1
脚本在 PowerShell 5.x(Windows PowerShell) 下,无法正确加载虚拟环境变量。 -
你看到的这句:
管道元素中的“.”后面的表达式生成无效的对象...
是因为$idf_exports
变量为空或格式不对,导致. $idf_exports
报错。
✅ 解决方案(推荐)
✅ 方法一:改用 PowerShell 7(pwsh.exe)
-
安装 PowerShell 7(如果你还没装):
-
或使用 winget:powershell
-
-
复制
winget install --id Microsoft.Powershell --source winget
-
-
打开 PowerShell 7(不是 Windows PowerShell),然后:powershell
-
复制
$env:SHELL = "pwsh.exe" .\export.ps1
✅ 这一步在 PowerShell 7 下几乎不会出错,ESP-IDF 官方也更推荐用它。
✅ 方法二:临时用 esp-idf-tools
的 cmd 环境
如果你不想装 PowerShell 7,可以先用 cmd 激活环境:
-
打开 CMD(不是 PowerShell)
-
运行:cmd
-
复制
D:\IDF\v5.4.1\esp-idf\export.bat
这个.bat
脚本是给 CMD 用的,不会出错。
✅ 方法三:手动激活虚拟环境(不推荐,除非你很熟)
你也可以手动进入 Python 虚拟环境:
powershell
复制
& D:\IDF\v5.4.1\esp-idf-tools\python_env\idf5.4_py3.11_env\Scripts\Activate.ps1
$env:IDF_PATH = "D:\IDF\v5.4.1\esp-idf"
但这样不会设置完整工具链路径,容易缺东西。
✅ 总结一句话
表格
复制
方案 | 操作 | 推荐程度 |
---|---|---|
✅ 安装 PowerShell 7 | winget install Microsoft.Powershell → 用 pwsh.exe 打开 → 设置 $env:SHELL = "pwsh.exe" → 运行 .\export.ps1 |
⭐⭐⭐⭐ |
✅ 用 CMD 激活 | 打开 CMD → 运行 export.bat |
⭐⭐⭐ |
❌ 继续用 Windows PowerShell | 会反复出错,不建议 | ⭐ |
我建议你直接装 PowerShell 7,一劳永逸,ESP-IDF 后续版本也会越来越依赖它。需要我帮你检查 PowerShell 7 是否装好了也可以。
全部评论