NCS Manual Setup working with Nordic Connect SDK for VS Code

Hello,

I have setup the NCS (Nordic Connect SDK) following the manual setup in WSL2 (Debian). 
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/nrf/installation/installing.html#additional-deps

I can build and flash an application fine using the command prompt.

I am trying to see if I can get my setup to work with the Nordic Connect SDK for VS Code extension. 

The extension finds the correct toolchain, however when I setup a build configuration and try to build, it fails on python dependencies.

I believe this happens because when following the install setup I used a virtual environment to install the python dependencies (outlined in step 5).

Is there anyway to configure the Nordic Connect SDK for VS Code extension to activate the virtual environment (venv) for the terminal it uses to compile the application?

Thanks in an advance for reading over my issue and any responses,

Himel

Parents
  • Hi Himel

    Could you generate the support information from VScode by clicking the generate support information button in the top right corner

    Also, are you running VScode from WSL2? 

    Regards

    Runar

  • Hi Runar,

    Here is the support information:

    IMPORTANT: The data below could contain sensitive or confidential information about your environment.
    If you do not wish this to be seen by others, please make sure to remove it before sharing.
    
    For help and support, visit the Nordic DevZone at https://devzone.nordicsemi.com/.
    
    {
      "platform": {
        "os": "linux",
        "osVersion": "#1 SMP Thu Oct 5 21:02:42 UTC 2023",
        "osKernel": "5.15.133.1-microsoft-standard-WSL2",
        "vscode": "1.85.1",
        "node": "v18.15.0"
      },
      "system": {
        "date": "2023-12-15T00:41:58.954Z",
        "vscodeRoot": "/home/himel/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2",
        "nrfConnectForDesktopInstalled": "unknown",
        "vscodeUptime": "00:41:21",
        "osUptime": "00:41:35",
        "cpu": "12th Gen Intel(R) Core(TM) i7-1265U"
      },
      "workspace": {
        "name": "hazy_project [WSL: Debian]",
        "workspaceFile": null,
        "folders": [
          "/home/himel/work/hazy_project"
        ]
      },
      "sdks": [
        {
          "version": "v2.5.0",
          "path": "/home/himel/work/hazy_project"
        }
      ],
      "activeBuild": "/home/himel/work/hazy_project/hazy/app/build",
      "apps": [
        {
          "workspace": "/home/himel/work/hazy_project",
          "uri": "/home/himel/work/hazy_project/hazy/app",
          "buildConfigurations": [
            {
              "id": "/home/himel/work/hazy_project/hazy/app/build",
              "name": "build",
              "boardId": "nrf5340dk_nrf5340_cpuapp",
              "type": "Zephyr",
              "isChild": false,
              "isStale": false,
              "taskBindings": {
                "build": [],
                "pristineBuild": [],
                "flash": [],
                "eraseAndFlash": []
              }
            }
          ]
        }
      ],
      "topdir": "/home/himel/work/hazy_project",
      "workspaceState": "workspace-ready",
      "toolchains": [],
      "connectedDevices": [],
      "deviceProvider": "nrfutil",
      "tools": {
        "/opt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc": "0.16.1",
        "/opt/SEGGER/JLink/JLinkExe": "7.88j",
        "/usr/local/bin/nrfjprog": "10.23.2",
        "nrfutil": "Not found",
        "/usr/bin/cmake": "3.25.1",
        "/home/himel/.local/bin/west": "1.2.0",
        "/usr/bin/python3": "3.11.2",
        "/usr/bin/ninja": "1.11.1",
        "/usr/bin/gperf": "3.1",
        "/usr/bin/dtc": "1.6.1",
        "gn": "Not found",
        "/usr/bin/git": "2.39.2",
        "gdbPath": "/opt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb"
      },
      "nrfutil": {
        "nrfutil-device": {
          "version": "2.0.0",
          "binPath": "/home/himel/.vscode-server/extensions/nordic-semiconductor.nrf-connect-2023.11.301-linux-x64/platform/nrfutil/bin/nrfutil-device"
        },
        "nrfutil-toolchain-manager": {
          "version": "0.14.1",
          "binPath": "/home/himel/.vscode-server/extensions/nordic-semiconductor.nrf-connect-2023.11.301-linux-x64/platform/nrfutil/bin/nrfutil-toolchain-manager"
        }
      },
      "environment": {
        "westEnv": {
          "ELECTRON_RUN_AS_NODE": "1",
          "HOME": "/home/himel",
          "PATH": "/opt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin:/home/himel/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/bin/remote-cli:/home/himel/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/home/himel/.local/bin:/home/himel/.local/bin",
          "ZEPHYR_BASE": "/home/himel/work/hazy_project/zephyr",
          "ZEPHYR_TOOLCHAIN_VARIANT": "zephyr",
          "USER": "himel"
        },
        "inherited": {
          "ELECTRON_RUN_AS_NODE": "1",
          "HOME": "/home/himel",
          "PATH": "/home/himel/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/bin/remote-cli:/home/himel/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/home/himel/.local/bin:/home/himel/.local/bin",
          "USER": "himel"
        },
        "toolchainPath": "PATH"
      },
      "terminal": {
        "defaultProfile": null
      },
      "config": {
        "nordic-semiconductor.nrf-connect": {
          "topdir": "",
          "toolchain": {
            "path": ""
          },
          "ozonePath": "",
          "applications": [
            "${workspaceFolder}/hazy/app"
          ],
          "applicationOptions": {},
          "kconfig": {
            "interface": "kconfig"
          },
          "west": {
            "env": {
              "$base": "terminal"
            }
          },
          "boardRoots": [],
          "taskBindings": {},
          "debugging": {
            "flash": true,
            "bindings": {},
            "justMyCode": true
          },
          "activeAppFollowActiveEditor": true,
          "deviceProvider": "",
          "flash": {
            "softreset": false,
            "erase": false,
            "recover": false
          },
          "enableTelemetry": true,
          "thirdpartyIntegration": {},
          "toolchainManager": {
            "indexURL": null,
            "installDirectory": null
          },
          "nrfutil": {
            "home": null
          },
          "defaultOpenAction": "ask"
        },
        "nordic-semiconductor.nrf-terminal": {
          "terminalMode": "character"
        }
      },
      "extensions": {
        "internal": {
          "nordic-semiconductor.nrf-connect": {
            "version": "2023.11.301",
            "path": "/home/himel/.vscode-server/extensions/nordic-semiconductor.nrf-connect-2023.11.301-linux-x64",
            "isActive": true
          },
          "nordic-semiconductor.nrf-terminal": {
            "version": "2023.10.17",
            "path": "/home/himel/.vscode-server/extensions/nordic-semiconductor.nrf-terminal-2023.10.17",
            "isActive": true
          },
          "nordic-semiconductor.nrf-devicetree": {
            "version": "2023.11.120",
            "path": "/home/himel/.vscode-server/extensions/nordic-semiconductor.nrf-devicetree-2023.11.120",
            "isActive": true
          },
          "nordic-semiconductor.nrf-kconfig": {
            "version": "2023.11.64",
            "path": "/home/himel/.vscode-server/extensions/nordic-semiconductor.nrf-kconfig-2023.11.64",
            "isActive": true
          }
        },
        "external": {
          "marus25.cortex-debug": null,
          "ms-vscode.cpptools": "1.18.5",
          "ms-vscode.js-debug": "1.85.0",
          "ms-vscode.vscode-js-profile-table": "1.0.8",
          "eamodio.gitlens": "14.6.0",
          "ms-python.python": "2023.22.1",
          "ms-python.vscode-pylance": "2023.12.1",
          "ms-vscode.cpptools-extension-pack": "1.3.0",
          "trond-snekvik.gnu-mapfiles": "1.1.0"
        }
      }
    }
    

    I am using vscode remote development feature - https://code.visualstudio.com/docs/remote/wsl-tutorial

    edit: Thought it might be worthwhile add the build output information:

     *  Executing task: nRF Connect: Generate config nrf5340dk_nrf5340_cpuapp for hazy/app 
    
    Building app
    west build --build-dir /home/himel/work/hazy_project/hazy/app/build /home/himel/work/hazy_project/hazy/app --pristine --board nrf5340dk_nrf5340_cpuapp --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DCONF_FILE=/home/himel/work/hazy_project/hazy/app/prj.conf
    
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: /home/himel/work/hazy_project/hazy/app
    -- CMake version: 3.25.1
    -- Found Python3: /home/himel/.local/pipx/venvs/west/bin/python (found suitable version "3.11.2", minimum required is "3.8") found components: Interpreter 
    -- Cache files will be written to: /home/himel/.cache/zephyr
    -- Zephyr version: 3.4.99 (/home/himel/work/hazy_project/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Found host-tools: zephyr 0.16.1 (/opt/zephyr-sdk-0.16.1)
    -- Found toolchain: zephyr 0.16.1 (/opt/zephyr-sdk-0.16.1)
    -- Found Dtc: /opt/zephyr-sdk-0.16.1/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") 
    -- Found BOARD.dts: /home/himel/work/hazy_project/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Generated zephyr.dts: /home/himel/work/hazy_project/hazy/app/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /home/himel/work/hazy_project/hazy/app/build/zephyr/dts.cmake
    Parsing /home/himel/work/hazy_project/zephyr/Kconfig
    Loaded configuration '/home/himel/work/hazy_project/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/home/himel/work/hazy_project/hazy/app/prj.conf'
    Configuration saved to '/home/himel/work/hazy_project/hazy/app/build/zephyr/.config'
    Kconfig header saved to '/home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: /opt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/himel/work/hazy_project/hazy/app/build
    -- west build: building application
    [1/140] Preparing syscall dependency handling
    
    [4/140] Generating include/generated/version.h
    -- Zephyr version: 3.4.99 (/home/himel/work/hazy_project/zephyr), build: v3.4.99-ncs1
    [6/140] Generating include/generated/driver-validation.h
    FAILED: zephyr/include/generated/driver-validation.h /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/driver-validation.h 
    cd /home/himel/work/hazy_project/hazy/app/build/zephyr && /home/himel/.local/pipx/venvs/west/bin/python /home/himel/work/hazy_project/zephyr/scripts/build/gen_kobject_list.py --validation-output /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/driver-validation.h --include-subsystem-list /home/himel/work/hazy_project/hazy/app/build/zephyr/misc/generated/struct_tags.json
    Traceback (most recent call last):
      File "/home/himel/work/hazy_project/zephyr/scripts/build/gen_kobject_list.py", line 62, in <module>
        import elftools
    ModuleNotFoundError: No module named 'elftools'
    [7/140] Generating include/generated/kobj-types-enum.h, include/generated/otype-to-str.h, include/generated/otype-to-size.h
    FAILED: zephyr/include/generated/kobj-types-enum.h zephyr/include/generated/otype-to-str.h zephyr/include/generated/otype-to-size.h /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/kobj-types-enum.h /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/otype-to-str.h /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/otype-to-size.h 
    cd /home/himel/work/hazy_project/hazy/app/build/zephyr && /home/himel/.local/pipx/venvs/west/bin/python /home/himel/work/hazy_project/zephyr/scripts/build/gen_kobject_list.py --kobj-types-output /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/kobj-types-enum.h --kobj-otype-output /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/otype-to-str.h --kobj-size-output /home/himel/work/hazy_project/hazy/app/build/zephyr/include/generated/otype-to-size.h --include-subsystem-list /home/himel/work/hazy_project/hazy/app/build/zephyr/misc/generated/struct_tags.json
    Traceback (most recent call last):
      File "/home/himel/work/hazy_project/zephyr/scripts/build/gen_kobject_list.py", line 62, in <module>
        import elftools
    ModuleNotFoundError: No module named 'elftools'
    [8/140] Generating include/generated/syscall_dispatch.c, include/generated/syscall_list.h
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/himel/work/hazy_project/hazy/app/build
    
     *  The terminal process terminated with exit code: 1. 
     *  Terminal will be reused by tasks, press any key to close it. 

  • Thanks
    could you try the following: 
    Override the default environment that west would use based on what the environment is within the virtual environment. This can be done in settings: https://nrfconnect.github.io/vscode-nrf-connect/reference/settings.html#nrf-connectwestenv
    Regards

    Runar

  • Hi Ruanr,

    I was trying to use that option before opening this issue. As a test, I even included sourcing the venv environment for my project in the .bashrc file. This is the output from bash -c printenv which is supposed to be used when the value is set to terminal. However I still get the same ModuleNotFoundError. 

    himel@Himel:~/work/hazy_project$ bash -c printenv
    SHELL=/bin/bash
    ZEPHYR_BASE=/home/himel/work/hazy_project/zephyr
    COLORTERM=truecolor
    WSL2_GUI_APPS_ENABLED=1
    TERM_PROGRAM_VERSION=1.85.1
    WSL_DISTRO_NAME=Debian
    NAME=Himel
    PWD=/home/himel/work/hazy_project
    LOGNAME=himel
    _=/usr/bin/printenv
    VSCODE_GIT_ASKPASS_NODE=/home/himel/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/node
    HOME=/home/himel
    LANG=en_US.UTF-8
    WSL_INTEROP=/run/WSL/41877_interop
    LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.swp=00;90:*.tmp=00;90:*.dpkg-dist=00;90:*.dpkg-old=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:
    VIRTUAL_ENV=/home/himel/work/hazy_project/.venv
    WAYLAND_DISPLAY=wayland-0
    GIT_ASKPASS=/home/himel/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/extensions/git/dist/askpass.sh
    VSCODE_GIT_ASKPASS_EXTRA_ARGS=
    TERM=xterm-256color
    USER=himel
    VSCODE_GIT_IPC_HANDLE=/run/user/1000/vscode-git-b0d7d8162f.sock
    DISPLAY=:0
    SHLVL=1
    VIRTUAL_ENV_PROMPT=(.venv) 
    XDG_RUNTIME_DIR=/run/user/1000/
    WSLENV=VSCODE_WSL_EXT_LOCATION/up
    VSCODE_GIT_ASKPASS_MAIN=/home/himel/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/extensions/git/dist/askpass-main.js
    PATH=/home/himel/work/hazy_project/.venv/bin:/home/himel/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/bin/remote-cli:/home/himel/.local/bin:/home/himel/work/hazy_project/.venv/bin:/home/himel/work/hazy_project/zephyr/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/home/himel/.local/bin:/home/himel/.local/bin:/home/himel/.local/bin
    DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
    HOSTTYPE=x86_64
    PULSE_SERVER=unix:/mnt/wslg/PulseServer
    TERM_PROGRAM=vscode
    VSCODE_IPC_HOOK_CLI=/run/user/1000/vscode-ipc-9acfc577-67e1-4f74-8d03-9f37633fc624.sock

    Am I using the correct value for this setting?

    Cheers,

    Himel

  • I have figured out my issue. I used pipx to install west. For some reason it finds that environment when running from the nordic connect extension vs the command line. Removing pipx fixes it.

Reply Children
Related