04-10-2015 02:25 PM
Hello,
Does anyone know how to run a Python function from LabVIEW? I know how to simply run a script using "Call System Exec" but not a specific function within a script. The reason behind this is the company I work for uses a lot of LabVIEW and a lot of Python and due to something of a schism between LabVIEW versus Python, we have a lot of code already written in one or the other that rather than duplicate, would be nice to use interchangeably.
I was experimenting with the LabPython library and by writing the script string:
"import <python module>
result = <python module>.<function>(<arguments>)"
I was able to accomplish my goal however only in the development environment. When I attempted to compile my VI to an LLB, I would get the error "1046 LabVIEW cannot initialize the script server. Ensure the server software is installed."
I'm now trying to accomplish the same thing using the Python DLL directly, bypassing the LabPython library but have so far been unsuccesful.
- Will
04-13-2015 06:43 PM
I do not know if this might be applicable to LabPython but that same error when using MatLab gets fixed by following these steps, maybe you could give it a try: http://digital.ni.com/public.nsf/allkb/862567530005F09C86256740005E5C9B
04-14-2015 02:39 AM - edited 04-14-2015 02:40 AM
LabPython being what it is, you have to take a bit care about a few things before it can possibly work in a built executable. First the script server for LabPython is the pyscript.dll file under <ProgramFiles>\National Instruments/<LabVIEW>/resource/script. This file needs to be copied to the <ProgramFiles>)\National Instruments\Shared\LabVIEW Run-Time<LabVIEW version>\script directory. However this script server is only a very thin wrapper around the lvPython.dll. This lvPython.dll needs to be present in the same directory that your build executable is.
Last but not least you have to make sure that your <app>.ini file contains a line PythonServer="<your python dll path>" that defines the location of the actual installed Python server dll.
04-14-2015 01:08 PM
"Last but not least you have to make sure that your <app>.ini file contains a line PythonServer="<your python dll path>" that defines the location of the actual installed Python server dll."
Is there a way to do this with a non-exe build? The final use of this is as an adapter in TestStand run using the runtime engine so technically the application is SeqEdit.exe. Creating an ini file for this however, still results in the same error. If I switch the adapter in TestStand to run the VI in LabVIEW development, it works fine unless I edit the LabVIEW.ini file to point to a fake DLL so it's definitely the ini thats causing me problems however since I don't have a typical app.ini file, it may be that the way LabPython stores the DLL location won't work in my case.
I was in the meantime able to call python directly without LabPython so it may be a moot point anyhow.