matter build fails in VCS extension but works with west

Hello,

I am getting the following python error when building matter examples using SDK 2.1.0 and MacOS. The same code will build successfully if you open a "terminal" using the Toolchain Manager and then running "west build" on the command line. It appears that is using the wrong python3. Instead of using python in the SDK it is using the one from /usr/local/bin. Is there a way to fix this?

cd /Volumes/Projects/karetrax/matter/light_switch/build/mcuboot && /usr/local/bin/python3.10 /opt/nordic/ncs/v2.1.0/bootloader/mcuboot/scripts/imgtool.py getpub -k /opt/nordic/ncs/v2.1.0/bootloader/mcuboot/root-rsa-2048.pem > /Volumes/Projects/karetrax/matter/light_switch/build/mcuboot/zephyr/autogen-pubkey.c
Traceback (most recent call last):
  File "/opt/nordic/ncs/v2.1.0/bootloader/mcuboot/scripts/imgtool.py", line 22, in <module>
    main.imgtool()
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/nordic/ncs/v2.1.0/bootloader/mcuboot/scripts/imgtool/main.py", line 121, in getpub
    key = load_key(key)
  File "/opt/nordic/ncs/v2.1.0/bootloader/mcuboot/scripts/imgtool/main.py", line 84, in load_key
    key = keys.load(keyfile)
  File "/opt/nordic/ncs/v2.1.0/bootloader/mcuboot/scripts/imgtool/keys/__init__.py", line 52, in load
    backend=default_backend())
  File "/usr/local/lib/python3.9/site-packages/cryptography/hazmat/backends/__init__.py", line 14, in default_backend
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/usr/local/lib/python3.9/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 6, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/usr/local/lib/python3.9/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 113, in <module>
    from cryptography.hazmat.bindings.openssl import binding
  File "/usr/local/lib/python3.9/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 14, in <module>
    from cryptography.hazmat.bindings._openssl import ffi, lib

  • Hi,

    I have started looking into your issue and will come back to you tomorrow.

    Best regards,

    Marte

  • Hi,

    Can you try in a new VS Code workspace, to ensure there are no workspace configs affecting the build?

    It seems to be an issue with the Python version used by imgtool, which is selected by Zephyr. Since SMP server also uses imgtool can you try building this sample and see if you get the same behavior there? If so, please copy the entire build log and add it here.

    Best regards,

    Marte

  • Before submitting this ticket I did create a brand new work space and project from the Matter templates.

    The problem is that Zephyr is selecting a Python version in the PATH vs using the one in the selected SDK toolchain. I bet if I change the system PATH to look in the SDK bin directories first, this will work fine. This is done automatically when you open a terminal using the Toolchain Manager interface.

    This seems to be a recurring problem. Have had the same issue with previous SDK releases. Not sure if it is unique to MacOS.

  • Hi,

    Yes, as I stated in my previous reply, imgtool is using the incorrect Python version, which is selected by Zephyr. Zephyr selects the first Python installation in path, so if you change the order in your system path then Zephyr should select a different one.

    As this might be a bug in the VS Code extension I will talk with the developers. For this it would be of great help to have some logs that show the issue, which is why I asked you to test with the SMP server sample and share the logs here. In addition, please generate support information in VS Code and upload that as well.

    Best regards,

    Marte

Related