Jump to content

What is the state-of-the-art of Python-LabVIEW integration?


Recommended Posts

I am just starting on trying to be able to use Python code from a LabVIEW application (mostly for some image analysis stuff).  This is for a large project where some programmers are more comfortable developing in Python than LabVIEW.  I have not done any Python before, and their seem to be a bewildering array of options; many IDE's, Libraries, and Python-LabVIEW connectors.  

So I was wondering if people who have been using Python with LabVIEW can give their experiences and describe what set of technologies they use.

  • Like 2
Link to post

Nice question James! I have tried to go down this route myself and had a very similar journey.

In the end I have decided to stick with VS Code for Python dev work as it seems to be gaining so much traction and is improving at a great rate.

None of the python connectors I tried worked very well. I would prefer to use the native one but it does not seem to support virtual environments which is what seems to be the preferred way of doing things in Python. In the end I rolled a simple TCP/IP client/server solution and was planning on using that to get data to/from Python.

But. I have no real experience with this so am going to shut up now for the rest of this thread and read every one else's answers with interest.

Link to post

My tuppence ... choose one, LabVIEW or Python.

You can create services which interact through TCPIP or REST API's but keep them separate.

If you have 20 python devs and one or two LabVIEW developers then you are on a hiding to nothing. Python won the war a long time ago and it's time to learn Python.

Not the answer you were probably looking for but you'll end up mostly doing IT and configuration trying to get your LabVIEW python stuff to work anywhere except your dev machine. 

  • Sad 2
Link to post
6 hours ago, Neil Pate said:

I would prefer to use the native one but it does not seem to support virtual environments which is what seems to be the preferred way of doing things in Python.

Can you say more about that?  What do you mean by a "virtual environment"?  I experimented with the native node in LabVIEW 2020 and I'm liking it so far.

Link to post
8 hours ago, drjdpowell said:

I've been investigating this: 

But I failed to get it to work.

What is the problem? As far as I remember I just had to tweak a path constant... However this is more than python. It's python in a Jupyter notebook (which is getting very popular in many circles)

Link to post

I've been a big advocate for the Enthought Python integration toolkit in the past.  Unfortunately, the product was discontinued when LabVIEW introduced the native python node.
I'm still scraping by on this product as I've not found a good alternative, and the built-in LabVIEW python node doesn't meet my needs.
Under the hood, the Enthought product was just a TCP link to Enthought's flavor of python called Canopy... which has also been discontinued.  :(
This product was fantastic for a few reasons:

  • Canopy environment could be packaged into a lightweight Python runtime engine, which can be zipped up and passed around with LabVIEW executables.  Made it easy to deploy the code to many machines.
  • 32/64 bit LabVIEW compatible
  • fast read/write of large data to/from Python

Relevant link:
https://support.enthought.com/hc/en-us/articles/360035630192-Toolkit-End-of-Life-Porting-to-LabVIEW-s-native-Python-support

I recognize that this probably isn't helpful... but a datapoint

 

  • Thanks 1
Link to post
9 minutes ago, bjustice said:

I've been a big advocate for the Enthought Python integration toolkit in the past.  Unfortunately, the product was discontinued when LabVIEW introduced the native python node.
I'm still scraping by on this product as I've not found a good alternative, and the built-in LabVIEW python node doesn't meet my needs.
Under the hood, the Enthought product was just a TCP link to Enthought's flavor of python called Canopy... which has also been discontinued.  :(
This product was fantastic for a few reasons:

  • Canopy environment could be packaged into a lightweight Python runtime engine, which can be zipped up and passed around with LabVIEW executables.  Made it easy to deploy the code to many machines.
  • 32/64 bit LabVIEW compatible
  • fast read/write of large data to/from Python

Relevant link:
https://support.enthought.com/hc/en-us/articles/360035630192-Toolkit-End-of-Life-Porting-to-LabVIEW-s-native-Python-support

I recognize that this probably isn't helpful... but a datapoint

 

It was not free and indeed was carrying along a few MB of extra payload in each executable/distro. That link will not be usable by new users (as far as I understand) since they don't sell licenses anymore.

Link to post

Correct, they don't sell licenses anymore.

Just trying to be helpful and provide another datapoint.  I'm in the same boat at the moment - looking for a good Python/LabVIEW integration solution, but there doesn't seem to be anything that has been able to eclipse the capabilities of the Enthought toolkit.

Link to post
13 hours ago, drjdpowell said:

Can you say more about that?  What do you mean by a "virtual environment"?  I experimented with the native node in LabVIEW 2020 and I'm liking it so far.

So again I am definitely not an expert but my understanding is that a virtual environment is like a small sandboxed instance where you can install packages and generally work without affecting all other python code on the system. I guess it's like nuget.

If you don't use a virtual environment when you install packages it affects the global python installation on your machine.

Seems like pretty sensible stuff (and hopefully what Project Dragon will do for LabVIEW). However I have not been able to get the native python node to work with a virtual environment.

Link to post
5 hours ago, Neil Pate said:

So again I am definitely not an expert but my understanding is that a virtual environment is like a small sandboxed instance where you can install packages and generally work without affecting all other python code on the system. I guess it's like nuget.

If you don't use a virtual environment when you install packages it affects the global python installation on your machine.

Seems like pretty sensible stuff (and hopefully what Project Dragon will do for LabVIEW). However I have not been able to get the native python node to work with a virtual environment.

Are you referring to Docker? Does this ring any bells?

Link to post
On 3/6/2021 at 6:25 AM, Neil Pate said:

So again I am definitely not an expert but my understanding is that a virtual environment is like a small sandboxed instance where you can install packages and generally work without affecting all other python code on the system. I guess it's like nuget.

If you don't use a virtual environment when you install packages it affects the global python installation on your machine.

Seems like pretty sensible stuff (and hopefully what Project Dragon will do for LabVIEW). However I have not been able to get the native python node to work with a virtual environment.

Though I see the value in that, I don't think that is a significant advantage in my case.  Actually a disadvantage, as my client is already overburdened with "too many things" complexity and would benefit from a standardized python environment.  I also want to minimize the complexity of install on a fresh computer, and I think the native node only requires python itself.

 

Link to post
3 hours ago, drjdpowell said:

Though I see the value in that, I don't think that is a significant advantage in my case.  Actually a disadvantage, as my client is already overburdened with "too many things" complexity and would benefit from a standardized python environment.  I also want to minimize the complexity of install on a fresh computer, and I think the native node only requires python itself.

 

Sure. But doing dev work on your own PC could then be potentially problematic if you have to support multiple different projects and implementations.

I do expect the native node to get better as time progresses and python slowly strangles all other languages.

Link to post
On 3/7/2021 at 2:22 PM, Neil Pate said:

Sure. But doing dev work on your own PC could then be potentially problematic if you have to support multiple different projects and implementations.

Hey, I haven't got even one project using python yet.   And my Dev PC uses virtual machines, which I already use for issues like developing with or without Vision installed.

Link to post

Side note: I am definitely going with the native node, in LabVIEW 2020.  I think NI is underselling it by providing examples that are far too simple (including no examples of cluster-to-tuple or how to hold state data in your py module).  I prototyped my analysis template py module yesterday and it went easy.  No head banging frustrations at all.

  • Like 2
Link to post
2 hours ago, drjdpowell said:

Side note: I am definitely going with the native node, in LabVIEW 2020.  I think NI is underselling it by providing examples that are far too simple (including no examples of cluster-to-tuple or how to hold state data in your py module).  I prototyped my analysis template py module yesterday and it went easy.  No head banging frustrations at all.

Would love to see your more sophisticated testing, especially the holding state data.

Link to post
7 hours ago, Neil Pate said:

Would love to see your more sophisticated testing, especially the holding state data.

Not sure it is sophisticated, but here is a simple implementation of an Example that increments a counter (state variable), with an error thrown if count exceeds a MaxCount (state variable).  The py Module is called from a LVOOP Object that encapsulates the Python instance.  The Class has methods that call the corresponding py-module functions.

Python Incrementer.zip

py module is this:

# Demo of a Python Module, to be called by LabVIEW

# Notes on Errors:
#  Return errors in a form matching the LabVIEW Error Cluster.  Examples:
#    Error = (False,0,"") # No Error
#    Error = (True,1,"MySource<Err>MyDescription") # 1==Error in input

import time  # used for sleep()

# Example of having global data (global just to this module):
Count = 0
MaxCount = 10

def Initialize():
        Error = (False,0,"") # No Error (change to indicate an error)
        return(Error,)

def GetCount():
        global Count
        return (Count);

def Increment():
        Error = (False,0,"") # No Error (change to indicate an error)
        global Count
        global MaxCount
        if Count >= MaxCount:
                Error=(True,1,"Increment<Err>Can't Increment as at MaxCount")
        else:
                Count += 1
                time.sleep(.3)  # Wait, to count slow enought to see
        return (Error,Count);

def SetMaxCount(NewMaxCount):
        Error = (False,0,"") # No Error (change to indicate an error)
        global MaxCount
        MaxCount = NewMaxCount
        return(Error,)

 

Link to post
3 hours ago, drjdpowell said:

Not sure it is sophisticated, but here is a simple implementation of an Example that increments a counter (state variable), with an error thrown if count exceeds a MaxCount (state variable).  The py Module is called from a LVOOP Object that encapsulates the Python instance.  The Class has methods that call the corresponding py-module functions.

Python Incrementer.zip 66.65 kB · 2 downloads

py module is this:

Just be aware:

Quote

Python version specifies the version of Python in which the Python session runs. This function supports Python of version 2.7 and 3.6 only. Although unsupported versions might work with the LabVIEW Python functions, NI recommends using supported versions of Python only.

 

Link to post
8 hours ago, ShaunR said:

Just be aware

Can't tell if that is just NI being overcautious, or there is an actual reason for that.  Python 2 was sunsetted  at the start of this year, so no one should use that.  I'm guessing the NI's testing was done against 3.6, as the latest available version when they originally developed the python node. 

 

Link to post
On 3/5/2021 at 9:17 PM, bjustice said:

I've been a big advocate for the Enthought Python integration toolkit in the past.  Unfortunately, the product was discontinued when LabVIEW introduced the native python node.

Very neat thanks for the background on a toolkit I didn't know existed.  I'm sure NI was in a "damned if you do/damned if you don't" situation, but this can be seen as another example of NI's first party solution, stifling 3rd party toolkits.  Also I generally don't mind bundling in stand alone binaries in cases like this if it means an easier experience for users, similar to bundling in the SQLite DLL in the build.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By kpaladiya
      I would like to build a model using image data and NI-cRIO-9063 and NI 9264 for voltage control.
      for image, I made a script in python using OpenCV libraries that detecting some points . For voltage control, I use cRIO-9063 with NI 9264 voltage controller.
      My question is, I am new in LabVIEW and I don't have any idea how can I make a loop for voltage control in python. Is there any library available in python that directly connect cRIO and NI 9264 devices? if not then how can I combine my image data(which is in python) with cRIO device? I need argent help.
    • By Makrem Amara
      Hi there,
      I am working on a machine vision project with LabVIEW.
      The camera will locate some parts and send their coordinates via TCP/IP 
      and I created a client also with LabVIEW to display these coordinates here is how the communication going.
      First, if the camera detects something then msg will be sent to the client to inform him.
      then if msg was received correctly client responds with another msg to request the coordinates. 
      at last, the server sends the coordinates to the client. 
      here I faced some problems
      1- the msg sent are with variable length ("x=0,y=0,Rz=0"==> "x=225,y=255,Rz=5" ==> "x=225,y=255,Rz=90"  length vary between 16 and 22 ) with the constant "byte to read " it will not display the full msg.
      2-the client works fine but at a certain time, it shows errors like ("LabVIEW: (Hex 0x80) Open connection limit exceeded";;;;;; "LabVIEW: (Hex 0x42) The network connection was closed by the peer. If you are using the Open VI Reference function on a remote VI Server connection, verify that the machine is allowed access by selecting Tools>>Options>>VI Server on the server side"
       
       





    • By Yaw Mensah
      I have installed Labview 2020 on Dedian Buster using the rpm to deb conversion method via alien. Due to Architecture mismatch i deleted the *i386.rpm files before conversion.
      My Problem is that after creating a project at "Build Specification"-> "rigth click" i am only able to select "Source Distribution". Application does not show up as an option. 
      I will be grateful for any suggestions.
      Thank you in advance.
    • By javier_r
      VIPM.io now allows you to post LabVIEW Resources, Ideas, and Tools. For example, you could post a link to a video tutorial or blog article about a package. You can also post ideas, like feature requests or new tools. Best of all, package developers are notified when you post your ideas and resources, and you can comment and discuss posts with the community. Take a look at this video to learn more: https://www.vipm.io/posts/664960df-f111-4e13-989a-24be8207182d/

    • By Shuvankar Das
      I want to connect My ccd camera with labview. The details of my system is given bellow. I cannot connect it please help   OS:  WINDOWS 7, 64bit   LabView Run-Time 2013(64-bit) NI-IMAQ 4.8 NI-IMAQdx 4.3   Camera: QICAM Monochrome Cooled (QIC-F-M-12-C) Model QICAM Resolution 1392 x 1040 Sensor 1/2" Sony ICX205 progressive-scan interline CCD Pixel Size 4.65 x 4.65µm Cooling Type Peltier thermoelectric cooling to 25˚C below ambient Digital Output 12 bit Video Output FireWire (IEEE 1394b) Max. Frame Rate 10 fps full resolution @ 12 bits Pixel Scan 20, 10, 5, 2.5MHz Mount Type C-mount optical format  
       
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.