Toolkit End of Life -- Porting to LabVIEW's native Python support

Enthought's Python Integration Toolkit for LabVIEW (PITL) is at end of life, and is no longer available for sale / licensing. Enthought will support existing customers for one year from date of purchase, as stated in the PITL license.

Background

When work started on the PITL a few years ago, there was no solid option for people who wanted to use Python and LabVIEW closely together, and Enthought was able to help by providing integration with both Python and the Canopy IDE product.

The landscape now is different... Python has exploded in popularity, and since LabVIEW 2018, customers now have a native mechanism for calling Python from LabVIEW.  The built-in Python Functions provide a seamless and low-complexity experience for calling Python from LabVIEW. Because the Python Node is a native LabVIEW component, the process of calling Python is substantially simplified; the Python Node plus two session-management VIs replace all 11 VIs in the Python Integration Toolkit; and there is first-class integration with NI's Application Builder.

Quick Reference

See also the Python palette reference in the official LabVIEW documentation.  Here is a summary of PITL VIs and their new LabVIEW-native equivalents:

Python Integration Toolkit LabVIEW 2018+ Python Functionality
New Session Open Python Session
Close Session Close Python Session
Call Python Node
Pack Not needed
Unpack Not needed
Get Value Python Node plus small Python function
Set Value Python Node plus small Python function
Delete Value Python Node plus small Python function
Exec String Python Node plus small Python function
Catch Exception Handle inside Python

Clear Objects

Not needed

Key Differences

Sessions

The main difference here is that a PITL session includes a reference to a single Python module, whereas the LabVIEW built-in Python sessions can have multiple modules per session. Instead of providing the Path to Python Module when the session is created, it should be provided as desired to each Python Node call.  There is no longer any need to start multiple sessions for different modules.

Interpreter discovery is also different; instead of the optional "Path to Python.exe" input used by the PITL, ensure that the directory containing the Python DLL is on the system path before launching LabVIEW.  When distributing applications that need to call Python, this replaces complex interpreter-discovery code with a requirement that the PATH environment variable be set correctly by the machinery installing Python.  LabVIEW will then pick up the DLL and handle further configuration automatically. Be sure to specify the desired version of Python; like the PITL, both Python 2 (2.7) and Python 3 (3.6) are currently supported by the LabVIEW Python Node.

Calling Python

With the built-in LabVIEW Python functionality, it is no longer necessary to Pack function arguments, or Unpack returned objects.  Likewise, Clear Objects is no longer needed to recover memory. Instead, simply wire your data directly to the Python Node inputs and outputs, and LabVIEW will handle all format conversion.  Like other LabVIEW functions that need to accept a variable number of inputs and outputs, you can resize the Python Node as needed depending on the function you call. The Python Node terminals will also automatically adapt to the LabVIEW data types you wire to them, replacing the PITL requirement that the correct polymorphic VI be selected.

There are also some data type differences.  First, sending clusters from LabVIEW to Python is now possible.  They arrive as tuples, so be sure to check the order of controls in your cluster to be sure it's what you expect.  Second, the LabVIEW Python Node supports arrays via conversion to Python lists. On the Python side, to convert to a numerical array, wrap each array argument in numpy.array(arg) before using.  You can then use the NumPy arrays as normal, including passing them to lower-level scientific libraries like SciPy.

Python helper functions

Some of the PITL functionality (Get/Set/Delete Value, Exec String) requires calling a small Python shim function in your module:

Get Value

def get_value(name):
    return globals()[name]

Set Value

def set_value(name, value):
    globals()[name] = value

Delete Value

def delete_value(name):
    del globals()[name]

Exec String

First, ensure you have installed the "six" Python package (for example, by running pip install six on the command line).  Then:

import six
def exec_string(string):
    six.exec_(string)

Handling specific exceptions

Instead of using the Catch Exception VI, this should be carried out inside your Python code, using the normal Python try/except machinery.

Have more questions? Submit a request

Comments

Powered by Zendesk