windows 环境 esp-idf 更新后报错 This script was called from a virtual environment, can not create a virtual environment again

.

.

.

.

.

报这个错是因为旧版本的 python 环境与新版本的不兼容,但是检测到旧版本的 python 环境还在,就不安装新版本的环境了。

1、首先把 C:\Espressif\python_env 文件夹改个名字,例如 python_env.bak。

2、然后重新执行 esp-idf 目录下的 .\install.ps1,这时候会重新安装新环境,例如C:\Espressif\python_env\idf5.3_py3.12_env。

再次运行 ESP-IDF PowerShell,可能出现新的错误:

Setting PYTHONNOUSERSITE, was not set
Get-Item : 找不到路径“C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe”,因为该路径不存在。
所在位置 C:\Espressif\Initialize-Idf.ps1:75 字符: 18
+ $IdfPythonDir = (Get-Item $PythonCommand).Directory.FullName
+                  ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Espressif\py...ipts\python.exe:String) [Get-Item], ItemNotFoundExcep
   tion
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

Using Python in
& : 无法将“C:/Espressif/python_env/idf5.2_py3.11_env/Scripts/python.exe”项识别为 cmdlet、函数、脚本文件或可运行程序的
名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 C:\Espressif\Initialize-Idf.ps1:80 字符: 2
+ &$PythonCommand --version
+  ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:/Espressif/py...ipts/python.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

这是因为虽然新的 python 环境安装成功了,但是 espidf 配置文件的路径还是旧的,查询路径:

PS D:\ProgramFiles\esp-idf> idf-env config get --property python --idf-id esp-idf-a1c90d57562a35d463d55b4a5218cc0e
C:/Espressif/python_env/idf5.2_py3.11_env/Scripts/python.exe

果然还是旧的路径。

执行命令 idf-env config edit 会弹出记事本窗口,在里面将 python 路径修改为新的(例如C:\Espressif\python_env\idf5.3_py3.12_env),再执行 ESP-IDF PowerShell 应该就不会报错了。

posted on 2025-03-21 18:34  0xCAFEBABE  阅读(261)  评论(0)    收藏  举报

导航