Build fail - Python version

We are currently using NCS V2.0.0 to compile a project for an nRF9160. I need to create a build script for compiling the code. When I compile from VSCode everything works. Next I use nRF Connect for Desktop, Toolchain Manager and the down arrow next to nRF Connect SDK v2.1.0, I select Open command prompt to make sure all my environment variables are set correctly. Then I go to our code directory. In VSCode I copy the build command and run it in command prompt. The build always fails with this message:

[61/428] Generating ../../tfm/CMakeCache.txt
FAILED: tfm/CMakeCache.txt
.....
-- Found assembler: C:/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
-- Found Python3: C:/Python310/python.exe (found version "3.10.5") found components: Interpreter
.....
ImportError: Module use of python38.dll conflicts with this version of Python.
CMake Error at tools/CMakeLists.txt:161 (message):
File generation failed

It is pointing to an incorrect version of Python. Next I used VSCode to compile to a different directory so I can compare a working and not working build. The difference between the two that really stood out is:

build directory\tfm\CMakeCache.txt

Can you please give me advice why the Python executable is not set correctly when compiling TFM?

Parents
  • Hello

    Is it correct that you are using 2.0.0 in VS Code and 2.1.0 in the command prompt?

    If this is correct, have you tried using 2.0.0 in the command prompt also?

    Best regards,

    Einar

Reply
  • Hello

    Is it correct that you are using 2.0.0 in VS Code and 2.1.0 in the command prompt?

    If this is correct, have you tried using 2.0.0 in the command prompt also?

    Best regards,

    Einar

Children
  • Hi Einar
    Thank you for helping me with this. Currently we are using V2.1.0 for everything. I did the following experiment:

    Created 2 folders:

    C:\Test\v20
    C:\Test\v21
    Into v20 I copied C:\ncs\v2.0.0\nrf\samples\nrf9160\at_client and into v21 I copied C:\ncs\v2.1.0\nrf\samples\nrf9160\at_client

    For v20, when I compile it in VSCode everthing works. Next I opened command prompt in Toolchain manager next to nRF Connect SDK v2.0.0. I copied the build command from VSCode and changed the build output folder:


    Microsoft Windows [Version 10.0.22000.1219]
    (c) Microsoft Corporation. All rights reserved.

    C:\ncs\v2.0.0>cd \test\v20

    C:\Test\V20>west build --build-dir c:\Test\V20\build_cmd c:\Test\V20 --pristine --board nrf9160dk_nrf9160_ns -- -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DCONF_FILE:STRING="c:/Test/V20/prj.conf"
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: C:/Test/V20
    -- Found Python3: C:/ncs/toolchains/v2.0.0/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v2.0.0/zephyr/.cache
    -- Zephyr version: 3.0.99 (C:/ncs/v2.0.0/zephyr)
    -- Found west (found suitable version "0.13.1", minimum required is "0.7.1")
    -- Board: nrf9160dk_nrf9160_ns, Revision: 0.7.0
    -- Found host-tools: zephyr 0.14.1 (C:/ncs/toolchains/v2.0.0/opt/zephyr-sdk)
    -- Found dtc: C:/ncs/toolchains/v2.0.0/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found toolchain: zephyr 0.14.1 (C:/ncs/toolchains/v2.0.0/opt/zephyr-sdk)
    -- Found BOARD.dts: C:/ncs/v2.0.0/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_ns.dts
    -- Generated zephyr.dts: C:/Test/V20/build_cmd/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: C:/Test/V20/build_cmd/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: C:/Test/V20/build_cmd/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: C:/Test/V20/build_cmd/zephyr/dts.cmake
    Parsing C:/ncs/v2.0.0/zephyr/Kconfig
    Loaded configuration 'C:/ncs/v2.0.0/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_ns_defconfig'
    Merged configuration 'c:/Test/V20/prj.conf'
    Configuration saved to 'C:/Test/V20/build_cmd/zephyr/.config'
    Kconfig header saved to 'C:/Test/V20/build_cmd/zephyr/include/generated/autoconf.h'

    warning: Experimental symbol NET_SOCKETS_OFFLOAD is enabled.

    -- The C compiler identification is GNU 10.3.0
    -- The CXX compiler identification is GNU 10.3.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    CMake Warning at C:/ncs/v2.0.0/zephyr/CMakeLists.txt:1803 (message):
    __ASSERT() statements are globally ENABLED


    Dropping partition 'nrf_modem_lib_trace' since its size is 0.
    Dropping partition 'nonsecure_storage' since it is empty.
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/Test/V20/build_cmd
    -- west build: building application
    [5/246] Generating include/generated/version.h
    -- Zephyr version: 3.0.99 (C:/ncs/v2.0.0/zephyr), build: v3.0.99-ncs1
    [55/246] Generating ../../tfm/CMakeCache.txt
    FAILED: tfm/CMakeCache.txt
    cmd.exe /C "cd /D C:\Test\V20\build_cmd\tfm && C:\ncs\toolchains\v2.0.0\opt\bin\cmake.exe -GNinja -DTFM_TOOLCHAIN_FILE=C:/ncs/v2.0.0/modules/tee/tf-m/trusted-firmware-m/toolchain_GNUARM.cmake -DCROSS_COMPILE=C:/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi -DCMAKE_BUILD_TYPE=MinSizeRel -DTFM_PLATFORM=C:/ncs/v2.0.0/nrf/modules/tfm/tfm/boards/nrf9160 -DTFM_LIB_MODEL=OFF -DBL2=FALSE -DMCUBOOT_IMAGE_NUMBER=1 -DTFM_EXCEPTION_INFO_DUMP=OFF -DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_SILENCE -DTFM_SPM_LOG_LEVEL=TFM_SPM_LOG_LEVEL_SILENCE -DTFM_PARTITION_PROTECTED_STORAGE=OFF -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=OFF -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INITIAL_ATTESTATION=OFF -DTFM_PARTITION_PLATFORM=ON -DTFM_PARTITION_AUDIT_LOG=OFF -DTFM_PARTITION_FIRMWARE_UPDATE=OFF -DCRYPTO_RNG_MODULE_DISABLED=FALSE -DCRYPTO_KEY_MODULE_DISABLED=TRUE -DCRYPTO_AEAD_MODULE_DISABLED=TRUE -DCRYPTO_MAC_MODULE_DISABLED=TRUE -DCRYPTO_HASH_MODULE_DISABLED=TRUE -DCRYPTO_CIPHER_MODULE_DISABLED=TRUE -DCRYPTO_ASYM_ENCRYPT_MODULE_DISABLED=TRUE -DCRYPTO_ASYM_SIGN_MODULE_DISABLED=TRUE -DCRYPTO_KEY_DERIVATION_MODULE_DISABLED=TRUE -DHAL_NORDIC_PATH=C:/ncs/v2.0.0/modules/hal/nordic -DNRF_ALLOW_NON_SECURE_RESET=ON -DCONFIG_TFM_HALT_ON_CORE_PANIC= -DSECURE_UART1=OFF -DNRF_DIR=C:/ncs/v2.0.0/nrf -DZEPHYR_BASE=C:/ncs/v2.0.0/zephyr -DCRYPTO_HW_ACCELERATOR=True -DPLATFORM_DEFAULT_UART_STDOUT=OFF -DPLATFORM_DEFAULT_ATTEST_HAL=OFF -DPLATFORM_DEFAULT_CRYPTO_KEYS=OFF -DPLATFORM_DEFAULT_ROTPK=OFF -DPLATFORM_DEFAULT_IAK=OFF -DPLATFORM_DEFAULT_NV_SEED=OFF -DPLATFORM_DEFAULT_OTP=OFF -DPLATFORM_DEFAULT_OTP_WRITEABLE=OFF -DPLATFORM_DEFAULT_PROVISIONING=OFF -DTFM_DUMMY_PROVISIONING=OFF -DCRYPTO_NV_SEED=OFF -DPLATFORM_NV_COUNTER_MODULE_DISABLED=TRUE -DPLATFORM_DEFAULT_NV_COUNTERS=OFF -DCRYPTO_STORAGE_DISABLED=TRUE -DCRYPTO_ENGINE_BUF_SIZE=1 -DNRF_SECURITY_SETTINGS="ZEPHYR_DOTCONFIG=C:/Test/V20/build_cmd/zephyr/.config GCC_M_CPU=cortex-m33 ARM_MBEDTLS_PATH=C:/ncs/v2.0.0/mbedtls ZEPHYR_AUTOCONF=C:/Test/V20/build_cmd/zephyr/include/generated/autoconf.h" -DTFM_MBEDCRYPTO_CONFIG_PATH:STRING=nrf-config.h -DTFM_MBEDCRYPTO_PLATFORM_EXTRA_CONFIG_PATH:STRING=nrf-config-user.h -DTFM_TEST_REPO_PATH=C:/ncs/v2.0.0/modules/tee/tf-m/tf-m-tests -DMBEDCRYPTO_PATH=C:/ncs/v2.0.0/nrfxlib/nrf_security/tfm -DPSA_ARCH_TESTS_PATH=C:/ncs/v2.0.0/modules/tee/tf-m/psa-arch-tests C:/ncs/v2.0.0/modules/tee/tf-m/trusted-firmware-m"
    -- The C compiler identification is GNU 10.3.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    -- Found Python3: C:/Python310/python.exe (found version "3.10.5") found components: Interpreter
    Traceback (most recent call last):
    File "C:\ncs\v2.0.0\modules\tee\tf-m\trusted-firmware-m\tools\tfm_parse_manifest_list.py", line 12, in <module>
    from jinja2 import Environment, BaseLoader, select_autoescape, TemplateNotFound
    File "C:\ncs\toolchains\v2.0.0\opt\bin\Lib\site-packages\jinja2\__init__.py", line 12, in <module>
    from .environment import Environment
    File "C:\ncs\toolchains\v2.0.0\opt\bin\Lib\site-packages\jinja2\environment.py", line 46, in <module>
    from .lexer import get_lexer
    File "C:\ncs\toolchains\v2.0.0\opt\bin\Lib\site-packages\jinja2\lexer.py", line 46, in <module>
    compile("f├╖├╖", "<unknown>", "eval")
    ImportError: Module use of python38.dll conflicts with this version of Python.
    CMake Error at tools/CMakeLists.txt:132 (message):
    File generation failed


    -- Configuring incomplete, errors occurred!
    See also "C:/Test/V20/build_cmd/tfm/CMakeFiles/CMakeOutput.log".
    See also "C:/Test/V20/build_cmd/tfm/CMakeFiles/CMakeError.log".
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\v2.0.0\opt\bin\cmake.EXE' --build 'c:\Test\V20\build_cmd'

    C:\Test\V20>


    It looks like it always fail while compiling TFM as part of the project. When I compare the build_vs\tfm\CMakeCache.txt and build_cmd\tfm\CMakeCache.txt there are a couple of differences but the one that I think gives the biggest clue is in the VSCode one there is this line:

    //Path to a program.
    PYTHON_PREFER_EXECUTABLE:FILEPATH=C:/ncs/toolchains/v2.0.0/opt/bin/python.exe

    This line is missing in in the build_cmd folder. I have attached both files.

    I tried the same with V2.1.0 and I get the same results.

    Thanks again for looking into this.

    Hubert

  • hjetschko said:
    Found Python3: C:/Python310/python.exe (found version "3.10.5") found components: Interpreter

    I believe this is your issue, CMake is trying to use the wrong Python version, even though Zephyr finds the correct version in the start of your log:

    hjetschko said:
    Found Python3: C:/ncs/toolchains/v2.0.0/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter

    You could try adding -DPYTHON_EXECUTABLE:FILEPATH="c:/ncs/toolchains/v2.0.0/opt/bin/python.exe" to your west build command.

    -Einar

  • Hi Einar. Thank you for the reply. I tested this, please see the new command below:

    west build --build-dir c:\Test\V20\build_cmd c:\Test\V20 --pristine --board nrf9160dk_nrf9160_ns -- -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DCONF_FILE:STRING="c:/Test/V20/prj.conf" -DPYTHON_EXECUTABLE:FILEPATH="c:/ncs/toolchains/v2.0.0/opt/bin/python.exe"

    Unfortunately I get the same result. If you try to compile at_client with this command, does it work for you?

    Hubert

  • Hello

    This turns out to be caused by the TF-M build system using its own build environment, so the Python version has to be set for that as well.

    To do this, add these lines to ncs/[version]/nrf/modules/tfm/zephyr/CMakeLists.txt :

    https://github.com/nrfconnect/sdk-nrf/commit/da20df3f5a59e26ea0887e2944e70af6d3e71ae7

    This issue is fixed in the NCS 2.2.0 release.

    -Einar

  • Hi Einar.

    Thank you, this solution worked very well.

    Regards, Hubert