Skip to content

CLion integration fails to source export.sh when non-system Python is in PATH (conda/homebrew), leading to CMake project loading failed (IDFGH-16650) #17749

@shengt25

Description

@shengt25

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.5.1

Operating System used.

macOS

How did you build your project?

CLion IDE

If you are using Windows, please specify command line type.

None

What is the expected behavior?

Following the official CLion tutorial (https://developer.espressif.com/blog/clion/), the project should load successfully in CLion after configuring the environment file with export.sh.

What is the actual behavior?

When using conda/miniconda for Python management, export.sh fails to detect the correct Python virtual environment in CLion, causing CMake project loading to fail with:

CMake Error at CMakeLists.txt:6 (include):
  include could not find requested file:

    /tools/cmake/project.cmake


CMake Error at CMakeLists.txt:8 (idf_build_set_property):
  Unknown CMake command "idf_build_set_property".


-- Configuring incomplete, errors occurred!

This occurs because export.sh detects system Python instead of conda Python. See More Information for details

Steps to reproduce.

  1. Install conda/miniconda with Python (such as 3.13) as base environment
  2. Make sure the default Python is now the one from conda/miniconda.
  3. Follow the ESP-IDF setup steps, run install.sh in terminal, this creates $IDF_TOOLS_PATH/python_env/idf5.5_py3.13_env
  4. Verify it works in terminal: source export.sh, successful
  5. Follow the CLion tutorial to set environment file to export.sh in Toolchain settings
  6. Try open and load a project in CLion

Expected: Project loads successfully
Actual: CMake error (see above)

Build or installation Logs.


Diagnostic report archive.

No response

More Information.

Why this happens:

CLion (and most IDEs) don't load user shell configurations like ~/.zshrc by design. When CLion executes export.sh, conda's PATH is not available, so export.sh falls back to system Python which has a different version than the one used during installation.

In the Clion environment file loading process, export.sh detects system Python (in my case, /usr/bin/python3 v3.9.6) instead of conda Python (in my case $HOME/miniconda3/bin/python v3.13.2).

Therefore, it tries to find the wrong path $IDF_TOOLS_PATH/python_env/idf5.5_py3.9_env while the correct one should be $IDF_TOOLS_PATH/python_env/idf5.5_py3.13_env.

This cause the following process fail and project doesn't setup correctly.

Debug findings:

I temporarily modified export.sh to add logging to track the issue:

  • Added echo statements to log Python detection results to $HOME/clion-idf-debug.log
  • Found that after CLion load the project, the log recorded that it detected /usr/bin/python3 (version 3.9.6)
  • Found that it was trying to access $IDF_TOOLS_PATH/python_env/idf5.5_py3.9_env (which doesn't exist)
    While the correct path created during installation was $IDF_TOOLS_PATH/python_env/idf5.5_py3.13_env

Workaround:

Create a wrapper script and use it as the environment file in CLion. For example if user is using miniconda installed in $HOME/miniconda3:

export PATH="$HOME/miniconda3/bin:$PATH"
source $IDF_PATH/export.sh

Suggested solutions:

Option 1: Update the CLion tutorial documentation to include a note about this limitation. That user need to create a wrapper script that initializes your Python environment before sourcing export.sh

Option 2: Have install.sh record the Python path during installation, and make export.sh export this recorded path first. And provide a command to update this recorded path when users change their Python environment.

Also, Maybe add some diagnostic messages in CMake scripts when something goes wrong, showing what is missing and environment variables that ESP-IDF requires.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions