python

Configure Python for use in Zephyr build system.

This module finds and configures Python for use in the Zephyr build system. It ensures a compatible Python version is available and sets up necessary environment variables and CMake variables.

Variables

The PYTHON_MINIMUM_REQUIRED variable is used to specify the minimum required Python version.

The following variables will be defined when this CMake module completes:

Search Process

The module searches for Python in the following order:

  1. Using the Python3_EXECUTABLE if already defined

  2. Using the WEST_PYTHON if defined

  3. Searching for “python” or “python3” in the system PATH and virtual environment

  4. Using CMake’s find_package(Python3) mechanism

The module verifies that any found Python meets the minimum version requirement.

Windows-Specific Configuration

On Windows systems, the module sets the PYTHONIOENCODING environment variable to “utf-8” to ensure consistent encoding behavior when Python is invoked from CMake.

Example Usage

include(python)

# Now PYTHON_EXECUTABLE can be used to invoke Python scripts
execute_process(COMMAND ${PYTHON_EXECUTABLE} my_script.py)