How to Debug Python Code Called From LabVIEW Python Node

Updated Aug 30, 2023

Environment

Software

  • LabVIEW

Programming Language

  • Python

This article describes a way to debug Python code, which is called from the Python Node in LabVIEW.
The example is based on the usage of Microsoft's ® Open Source Editor Visual Studio Code ®, which is later abbreviated with VS Code.

Note 1: The steps are valid only valid for Python being run in non-virtual environment.
Note 2: The steps were tested with Python 3.9 for 32-bit and 64-bit, and for Python 3.8 in 64-bit. Python 3.8 in 32-bit did not work in the tests.
Note 3: The tested LabVIEW versions are 2021 SP1 and 2022 Q3, both in 32-bit and 64-bit.

  1. Install an extension to VS Code which supports Python debugging, e.g. the the one by Microsoft.
  2. If you are using the debugger for the first time, it will give you an option to create a launch.json file.
  3. Create the launch.json file. While creating the json, choose the option "Attach using Process ID". Choosing this let's you attach to the NIPythonHost exe process.
  4. On LabVIEW side, put a breakpoint on the CallPythonNode.
  5. Once you run the VI, the VI will pause at the CallPythonNode. If you open the TaskManager at this stage you will see the NIPythonHost.exe has started running.
  6. Go back to VS Code and choose Run->Start Debugging (or F5) and choose the NIPythonHost.exe process. It will then attach to this process.
  7. Go back to LabVIEW and hit continue on the VI.

You should now be able to debug the python code.