From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python Node in LV2018

Hi,

I have kind of a similar question!
I'm trying to send cluster data from labview to python through python node, but so far I have no clue how labview send cluster data to python (I mean in what format or form), have tried many python parsing options but still getting an error 

LabVIEW: (Hex 0x687) There was an error in executing the specified function. Python returned the following error: <class 'TypeError'> bad argument type for built-in operation

0 Kudos
Message 21 of 41
(6,048 Views)

You can treat LabVIEW clusters in Python as Tuples and access their elements accordingly. Please see the below example where we multiply two integers from a cluster using a Python function.

 

 python_multiply.png

 

 lv_python_node_cluster.png

It's worth noting that the Python Node supports the following data types:

- Numerics

- Arrays, including multi-dimensional arrays

- Strings

- Clusters

 

Python Node

http://zone.ni.com/reference/en-XX/help/371361R-01/glang/python_node

0 Kudos
Message 22 of 41
(6,029 Views)

I've discovered another slight weirdness with the LabVIEW support for Python. The latest version of Ananconda Python has been switched to Python 3.7 - so on a newly installed laptop, I have Ananconda3 in C:\ProgramData\Ananaconda3, and within that I created a python3.6 environment which lives in C:\ProgragramData\Anaconda3\envs\py36\.

Now I know that I need to make sure that LabVIEW 2018 can find the python install in the path, and I see in the documentation that LabVIEW supports 2.7 and 3.6 only, so I keep all other bits of Ananconda out of my PATH envornment variable and put C:\ProgramData\Anaconda3\envs\py36 at the start of the part, so the 3.6 Python is the first python to be found. I've made sure that everything is 64bit and opening up a command window does indeed give me 64bit Python 3.6 when I run python.exe.

Trying to use the LabVIEW Python nodes fails on the Open Python Session node with an Error 1671 "Error Creating Host Process". This is before trying to do anything in terms of calling a script. Telling LabVIEW to open other Python versions (e.g. 3.7,3.5,36) all give errors which seem sensible - not found or not supported python versions.

Changing the path to pint to the 'base' Python environment (i.e. 3.7 in C:\ProgramData\Anaconda3\) and telling LabVIEW to open a session to the allegedly unsupported 3.7 seems to work just fine....

Which is all fine, but there seems to be a serious lack of documentation about how to actually configure things to make LabVIEW and Python talk to each other...

--
Gavin Burnell
Condensed Matter Physics Group, University of Leeds, UK
http://www.stoner.leeds.ac.uk/
Message 23 of 41
(5,967 Views)

I had too a hard time. Installed various things...

 

For me the best solution is: Get Python 3.6.0 from https://www.python.org/

                                            Set the System variables Path to the directory

                                            ( normally C:\Users\User\AppData\Local\Programs\Python\Python36-32)

                                            go to cmd and check the version with command: python --version

                                            and then install packages which are needed like aurelian explained

 

1. in the command prompt write "cd C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts" so all the other command will occur in this folder.
2. type "pip install numpy" and the other libraries that you want. I installed matplotlib, scipy, scikit-learn, pillow, pandas, tensorflow (compatible just with Python 64bits) and keras.

 

Thats what worked for me.

0 Kudos
Message 24 of 41
(5,945 Views)

In fact some more testing showed that numpy in the current Anaconda Python distribution based on 3.7 doesn't load when called from the Python Node - which is a little annoying as it means I now have to keep a miniconda based 3.6 install of Python around for LabVIEW on top of the "full-fat" Anaconda distribution for coding in Python.

--
Gavin Burnell
Condensed Matter Physics Group, University of Leeds, UK
http://www.stoner.leeds.ac.uk/
0 Kudos
Message 25 of 41
(5,940 Views)

@gb119 wrote:

In fact some more testing showed that numpy in the current Anaconda Python distribution based on 3.7 doesn't load when called from the Python Node - which is a little annoying as it means I now have to keep a miniconda based 3.6 install of Python around for LabVIEW on top of the "full-fat" Anaconda distribution for coding in Python.


Could you create a conda env with 3.6 in it? Instead full installation of Miniconda?

0 Kudos
Message 26 of 41
(5,543 Views)

I did try that but it gave some errors - I'm afraid I can't remember now what the problem was - something on the lines of it not being able to find the correct dll (even after I fixed the path). In the end it seemed easier to just go with miniconda and a 3.6 install. Hopefully NI will update 2019 to work with 3.7 as well.

--
Gavin Burnell
Condensed Matter Physics Group, University of Leeds, UK
http://www.stoner.leeds.ac.uk/
0 Kudos
Message 27 of 41
(5,539 Views)

Hello !Can i ask you a question?

I write a vi as follows,but it always send me this error.i don't konw how to deal it.could you tell me how to do? If my python has something wrong?图片.png

 

 
0 Kudos
Message 28 of 41
(4,549 Views)

Hello, did you tried to return an array? When I use the initial Python3.6, it works well. However, when I install numpy, even I do not import it, array still can not be returned.

0 Kudos
Message 29 of 41
(4,380 Views)

I think you have to convert the arrays back to lists before you return them to LabVIEW.  It would be nice if LabVIEW's Python node supported numpy arrays (since numpy is the defacto standard in the Python world for handling numerical data) - it would also be nice if Python > 3.6.6ish worked 🙂

--
Gavin Burnell
Condensed Matter Physics Group, University of Leeds, UK
http://www.stoner.leeds.ac.uk/
0 Kudos
Message 30 of 41
(4,372 Views)