Developer Center Resources

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Python Code from LabVIEW

This VI sends inputs to a simple Python script, and returns its output.  The basic method could be used to call code from many different languages, like Python, Perl, and Tcl.

Requirements: LabVIEW, Python

Instructions

  1. Download the simple Python script AddNumbers.py attached below.
  2. Download Calling Python Script.vi (or the PNG code snippet).
  3. Place the Python script and the VI in the same folder (this is simply expected by the example, and could be changed).

VI Details

  1. Build path to Python script, which is expected to be in the same folder as this VI.  Again, the Python script could be moved, but the code would have to reflect that change.
  2. Create the command line argument, in the form of pythonpath scriptpath int32 int32.  Quotation marks are used for the path, in case there are spaces.
  3. Execute the  argument.  The run in minimized, so that the command window does not quickly appear and disappear.
  4. Convert the string output from Python to an int.

Chris Bolin
LabVIEW Partner Program, CLA
Download All
Comments
Tom_Hawkins
Member
Member
on

This isn't really any more than an example of how to use System Exec, though I suppose that'll be useful to some people.

What happens if I want to pass parameters to a Python script that contain spaces or reserved characters - is there an easy way to make sure they get quoted or escaped correctly or is it up to the LabVIEW programmer to figure this out?

PrimaryKey
NI Employee (retired)
on

Or you can use this toolkit https://forums.ni.com/t5/LabVIEW-APIs-Documents/Open-Python-Interface/tac-p/3613384#M228

Piotr Kruczkowski
Certified TestStand Architect
Certified LabVIEW Architect
carrasquel
Member
Member
on

Hello everybody I just did a new entry on my blog about an alternative on how you can integrate Python and LabVIEW

 

http://bit.ly/2pMSARJ

If any question or doubt don't hesitate to comment or contact me 🙂

AWK073
Member
Member
on

PrimaryKey 

carrasquel

both links are not opening which you guys have given above.

carrasquel
Member
Member
on
Contributors