ESP-IDF 5 Issue FYI - "Please use idf.py only in an ESP-IDF shell environment."

This happened to me, and will possibly affect other PlatformIO-users, so putting this here:

After doing some monkey-debugging of the not very error-reporting idf.py, I found that the actual error is that the esp-idf-monitor pip package is not installed for some reason.
So basically pip install esp-idf-monitor fixes it.

How to reproduce this issue?

cc: @valeros

Sorry, but I have no idea.
I have had issues with my development environments for days now, I have basically tried everything, and at one point this happened.
I think that there might be some issue with the ESP-IDF plugin for VSCode.
When I have sorted all those troubles out, perhaps I know more.
But just if this happens to someone else.

You don’t need this plugin when using the ESP-IDF framework in pair with PlatformIO. Could you uninstall that plugin and try this example https://registry.platformio.org/platforms/platformio/espressif32/examples/espidf-hello-world ?

I removed it, It did not help, I am afraid.
My problem is that I am getting this:

Resolving TTGO-LoRa32-v1 dependencies...
Already up-to-date.
Updating metadata for the vscode IDE...
UserSideException: Processing TTGO-LoRa32-v1 (platform: https://github.com/platformio/platform-espressif32.git#v6.0.1; framework: espidf; board: ttgo-lora32-v1)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/ttgo-lora32-v1.html
PLATFORM: Espressif 32 (6.0.1+sha.33f2e6e) > TTGO LoRa32-OLED V1
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf @ 3.50000.0 (5.0.0) 
 - tool-cmake @ 3.16.4 
 - tool-esptoolpy @ 1.40400.0 (4.4.0) 
 - tool-ninja @ 1.9.0 
 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0) 
 - toolchain-xtensa-esp32 @ 11.2.0+2022r1
Reading CMake configuration...
TypeError: 'NoneType' object is not iterable:
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/main.py", line 175:
    env.SConscript("$BUILD_SCRIPT")
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/main.py", line 312:
    target_elf = env.BuildProgram()
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Util/envs.py", line 242:
    return self.method(*nargs, **kwargs)
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/tools/piobuild.py", line 61:
    env.ProcessProgramDeps()
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Util/envs.py", line 242:
    return self.method(*nargs, **kwargs)
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/tools/piobuild.py", line 121:
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Util/envs.py", line 242:
    return self.method(*nargs, **kwargs)
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/tools/piobuild.py", line 342:
    SConscript(env.GetFrameworkScript(name), exports="env")
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 662:
    return method(*args, **kw)
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 1332:
    build_components(env, framework_components_map, PROJECT_DIR)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 860:
    components_map[k]["lib"] = build_library(
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 282:
    lib_objects = compile_source_files(
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 638:
    build_envs = prepare_build_envs(config, default_env, debug_allowed)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 603:
    for cg in target_compile_groups:
========================== [FAILED] Took 2.19 seconds ==========================

Sorry, missed the hello-world-link, will try that.

Actually, it didn’t build, not sure if it is related:

Compiling .pio/build/esp32-c3-devkitm-1/bootloader/esp_system/esp_err.o
Indexing .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/esp_hw_support/libesp_hw_support.a
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/hal/mpu_hal.o
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/hal/efuse_hal.o
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/hal/esp32c3/efuse_hal.o
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/hal/mmu_hal.o
Archiving .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/esp_rom/libesp_rom.a
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/hal/wdt_hal_iram.o
Indexing .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/esp_rom/libesp_rom.a
Archiving .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/esp_system/libesp_system.a
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/hal/cache_hal.o
Indexing .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/esp_system/libesp_system.a
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/log/log.o
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/log/log_buffers.o
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/log/log_noos.o
Compiling .pio/build/esp32-c3-devkitm-1/bootloader/bootloader/subproject/components/micro-ecc/uECC_verify_antifault.o
Generating partitions .pio/build/esp32-c3-devkitm-1/partitions.bin
Archiving .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/hal/libhal.a
Indexing .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/hal/libhal.a
Archiving .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/log/liblog.a
Indexing .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/log/liblog.a
Archiving .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/micro-ecc/libmicro-ecc.a
Indexing .pio/build/esp32-c3-devkitm-1/bootloader/esp-idf/micro-ecc/libmicro-ecc.a
Linking .pio/build/esp32-c3-devkitm-1/bootloader.elf
Building .pio/build/esp32-c3-devkitm-1/bootloader.bin
Traceback (most recent call last):
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/entity.py", line 152, in _get_infos_from_file
    results = parser.parseString(info.content, parseAll=True)
  File "/Users/nicklasborjesson/.platformio/penv/.espidf-5.0.0/lib/python3.10/site-packages/pyparsing/util.py", line 256, in _inner
    return fn(self, *args, **kwargs)
  File "/Users/nicklasborjesson/.platformio/penv/.espidf-5.0.0/lib/python3.10/site-packages/pyparsing/core.py", line 1190, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found 'default'  (at char 1), (line:2, col:1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen.py", line 183, in <module>
    main()
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen.py", line 159, in main
    mapping_rules = generation_model.generate(sections_infos)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/generation.py", line 514, in generate
    root_node.insert(entity, sections, target, flags, entities)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/generation.py", line 241, in insert
    self.child_placement(entity, sections, target, flags, sections_db)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/generation.py", line 233, in child_placement
    child.insert(entity, sections, target, flags, sections_db)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/generation.py", line 241, in insert
    self.child_placement(entity, sections, target, flags, sections_db)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/generation.py", line 233, in child_placement
    child.insert(entity, sections, target, flags, sections_db)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/generation.py", line 241, in insert
    self.child_placement(entity, sections, target, flags, sections_db)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/generation.py", line 296, in child_placement
    found_sections = sections_db.get_sections(self.parent.name, self.name)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/entity.py", line 197, in get_sections
    obj = self._match_obj(archive, obj)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/entity.py", line 183, in _match_obj
    objs = self.get_objects(archive)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/entity.py", line 176, in get_objects
    self._process_archive(archive)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/entity.py", line 164, in _process_archive
    parsed = self._get_infos_from_file(stored)
  File "/Users/nicklasborjesson/.platformio/packages/framework-espidf@3.50000.0/tools/ldgen/ldgen/entity.py", line 154, in _get_infos_from_file
    raise ParseException('Unable to parse section info file ' + info.filename + '. ' + p.msg)
pyparsing.exceptions.ParseException: Unable to parse section info file /Users/nicklasborjesson/Documents/PlatformIO/Projects/platform-espressif32-develop/examples/espidf-hello-world/.pio/build/esp32-c3-devkitm-1/esp-idf/esp_event/libesp_event.a. Expected end of text  (at char 0), (line:1, col:1)
*** [.pio/build/esp32-c3-devkitm-1/sections.ld] Error 1
esptool.py v4.4
Creating esp32c3 image...
Merged 1 ELF section
Successfully created esp32c3 image.
================================================================================= [FAILED] Took 61.69 seconds =================================================================================

Environment         Status    Duration
------------------  --------  ------------
esp32dev            FAILED    00:00:58.910
esp32-s2-kaluga-1   FAILED    00:03:14.781
esp32-c3-devkitm-1  FAILED    00:01:01.694

Strangely, if I change prepare_build_envs work to not crashing on missing compileGroups in my project,( the first ‘NoneType’ object is not iterable dump) as so:

def prepare_build_envs(config, default_env, debug_allowed=True):
    build_envs = []

    target_compile_groups = config.get("compileGroups")
# Added this:
    if (target_compile_groups == None):
        return []

… I end up with the error in the second dump; “Expected end of text, found ‘default’”.
There seems to be some problem somewhere.
I think I have reinstalled and removed everything that I can think of as well.

@valeros, could you help here?

PLATFORM: Espressif 32 (6.0.1+sha.33f2e6e) > TTGO LoRa32-OLED V1

The platform version you’re using is quite outdated. Have you tried compiling the same example but with the latest stable v6.3.2? Just open the PlatformIO Home page in the IDE, navigate to the Platforms tab and update Espressif 32 to the latest available.

I am afraid that I am having the same problems.

Resolving TTGO-LoRa32-v1 dependencies...
Already up-to-date.
Updating metadata for the vscode IDE...
UserSideException: Processing TTGO-LoRa32-v1 (platform: https://github.com/platformio/platform-espressif32.git#v6.3.2; framework: espidf; board: ttgo-lora32-v1)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/ttgo-lora32-v1.html
PLATFORM: Espressif 32 (6.3.2+sha.eb7eba4) > TTGO LoRa32-OLED V1
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf @ 3.50002.230601 (5.0.2) 
 - tool-cmake @ 3.16.4 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-ninja @ 1.9.0 
 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0) 
 - toolchain-xtensa-esp32 @ 11.2.0+2022r1
Removing an oudated IDF virtual environment
Creating a new virtual environment for IDF Python dependencies
Installing ESP-IDF's Python dependencies
Collecting urllib3<2
  Using cached urllib3-1.26.16-py2.py3-none-any.whl (143 kB)
Collecting cryptography~=41.0.1
  Using cached cryptography-41.0.2-cp37-abi3-macosx_10_12_x86_64.whl (2.8 MB)
Collecting future>=0.18.3
  Using cached future-0.18.3-py3-none-any.whl
Collecting pyparsing~=3.0.9
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Collecting kconfiglib~=14.1.0
  Using cached kconfiglib-14.1.0-py2.py3-none-any.whl (145 kB)
Collecting idf-component-manager~=1.2.3
  Using cached idf_component_manager-1.2.3-py3-none-any.whl (116 kB)
Collecting cffi>=1.12
  Using cached cffi-1.15.1-cp310-cp310-macosx_10_9_x86_64.whl (179 kB)
Collecting requests-toolbelt
  Using cached requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)
Collecting click
  Using cached click-8.1.6-py3-none-any.whl (97 kB)
Collecting requests<3
  Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Collecting tqdm<5
  Using cached tqdm-4.65.0-py3-none-any.whl (77 kB)
Collecting contextlib2>0.6.0
  Using cached contextlib2-21.6.0-py2.py3-none-any.whl (13 kB)
Collecting colorama
  Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting packaging
  Using cached packaging-23.1-py3-none-any.whl (48 kB)
Collecting requests-file
  Using cached requests_file-1.5.1-py2.py3-none-any.whl (3.7 kB)
Collecting schema
  Using cached schema-0.7.5-py2.py3-none-any.whl (17 kB)
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting cachecontrol[filecache]>0.12.6
  Using cached cachecontrol-0.13.1-py3-none-any.whl (22 kB)
Collecting pyyaml>5.2
  Using cached PyYAML-6.0.1-cp310-cp310-macosx_10_9_x86_64.whl (189 kB)
Collecting msgpack>=0.5.2
  Using cached msgpack-1.0.5-cp310-cp310-macosx_10_9_x86_64.whl (74 kB)
Collecting filelock>=3.8.0
  Using cached filelock-3.12.2-py3-none-any.whl (10 kB)
Collecting pycparser
  Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.2.0-cp310-cp310-macosx_10_9_x86_64.whl (126 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2023.5.7-py3-none-any.whl (156 kB)
Installing collected packages: msgpack, urllib3, tqdm, six, pyyaml, pyparsing, pycparser, packaging, kconfiglib, idna, future, filelock, contextlib2, colorama, click, charset-normalizer, certifi, schema, requests, cffi, requests-toolbelt, requests-file, cryptography, cachecontrol, idf-component-manager
Successfully installed cachecontrol-0.13.1 certifi-2023.5.7 cffi-1.15.1 charset-normalizer-3.2.0 click-8.1.6 colorama-0.4.6 contextlib2-21.6.0 cryptography-41.0.2 filelock-3.12.2 future-0.18.3 idf-component-manager-1.2.3 idna-3.4 kconfiglib-14.1.0 msgpack-1.0.5 packaging-23.1 pycparser-2.21 pyparsing-3.0.9 pyyaml-6.0.1 requests-2.31.0 requests-file-1.5.1 requests-toolbelt-1.0.0 schema-0.7.5 six-1.16.0 tqdm-4.65.0 urllib3-1.26.16

[notice] A new release of pip is available: 23.0.1 -> 23.2
[notice] To update, run: python -m pip install --upgrade pip
Reading CMake configuration...
TypeError: 'NoneType' object is not iterable:
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/main.py", line 175:
    env.SConscript("$BUILD_SCRIPT")
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/main.py", line 312:
    target_elf = env.BuildProgram()
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Util/envs.py", line 242:
    return self.method(*nargs, **kwargs)
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/tools/piobuild.py", line 61:
    env.ProcessProgramDeps()
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Util/envs.py", line 242:
    return self.method(*nargs, **kwargs)
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/tools/piobuild.py", line 121:
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Util/envs.py", line 242:
    return self.method(*nargs, **kwargs)
  File "/Users/nicklasborjesson/.platformio/penv/lib/python3.10/site-packages/platformio/builder/tools/piobuild.py", line 342:
    SConscript(env.GetFrameworkScript(name), exports="env")
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 662:
    return method(*args, **kw)
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/Users/nicklasborjesson/.platformio/packages/tool-scons/scons-local-4.5.2/SCons/Script/SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 1382:
    build_components(env, framework_components_map, PROJECT_DIR)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 874:
    components_map[k]["lib"] = build_library(
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 284:
    lib_objects = compile_source_files(
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 652:
    build_envs = prepare_build_envs(config, default_env, debug_allowed)
  File "/Users/nicklasborjesson/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 614:
    for cg in target_compile_groups:
========================= [FAILED] Took 70.51 seconds =========================

I think I have it narrowed down somewhat, it probably has something to do when a component in the components folder has its own idf_component.yml with dependencies.
(note that idf.py build does not have any problems it seems)

I will create a new topic for that, basically I meant this topic just for the exact purpose of the subject. Self-hijacked it…

It was created here:

@ivankravets I am having this issue in vscode using the ESP-IDF shell command on Linux. I am not using platformIO, maybe I should as somewhere else? Please advise.
Thank you.

@chrisjones79
Note that this thread has two issues, the first was resolved in the first post and has nothing to do with PlatformIO but might make people think they have PlatformIO-issues, the second is another one was PlatformIO-related. Have you tried the solution in the first?

Thanks @nicklasb I have not tried to install the manager via pip. The reason for that is because when I use VScode, with an open ESP-IDF project, I then open an ESP-IDF terminal. It is labeled accordingly, instead of bash, so I assume the command worked.

However, in this new ESP-IDF terminal, I do not seem to have the ESP-IDF environment activated.

me@young-pup:~/Documents/code/esp/SeeHereThen$ idf.py
idf.py: command not found

I think either my .bashrc or .profile (I’m not sure which as I’m a linux noob(I know one is for interactive shells tho)) is interfering with the terminal creation because I activate a pyenv shell from both of those files. Like so: eval "$(pyenv init -)" in the .profile file.

I made a mistake asking this question in this thread. Apologies, I will start a new question.

Your question seems relevant? It was rather my detour in the above questions that wasn’t?

I had the same problem in the ESP-IDF terminal, and that o solved with the pip install esp-idf-monitor command.

The problem is a bug somewhere in the ESP-IDF platform installation, and running the pip command amends the issue.

Ah, ok. Thanks.

So, I think my issue comes from the way I have configured VScode. I am not getting the ESP-IDF python environment activated when I open an ESP-IDF terminal.

I can call export.sh in the terminal to get rid of the command not found response but then I arrive at your problem. You’ve already looked at idf.py and saw the import statements that are tried which is why you’ve recommended using pip to install the idf_component_manager.

In my case, I know that the idf_component_manager is installed already in the virtual environment but my environment isn’t getting activated automatically when the ESP-IDF terminal command is invoked in VScode.

In that case, I would completely delete the ESP-IDF installation in your home folder, restart vscode and let the plugin reinstall it. On my Mac, I remove these folders:
~/.espressif
~/esp