LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a .pyd file in Call library Function Node

Hi, 

 

I am looking to use a external library but have a python Package pyd file for it rather than a dll. According to a google search this should behave like a dll. When I call it through a Call Library Function Node I can see the functions that are contained in it but I get a broken run arrow saying that the library has failed to load. 

Does anybody know how I can either convert this to a dll or convince LabVIEW to accept it as a dll? 

 

 

 

image.png

0 Kudos
Message 1 of 10
(3,870 Views)

I use .pyd files quite a few times.

 

CLFN_pyd.png

My guess is that a dependency of that library is not locatable (ie. in your PATH).  I like to use the following tool to check:

 

https://github.com/lucasg/Dependencies

 

Just open your pyd file in the gui and check for errors.  

Message 2 of 10
(3,791 Views)

Hi,

 

To begin with, my problem is exactly the same as the one that has been posted on stack overflow, described here: "https://stackoverflow.com/questions/71034793/after-making-pyd-with-cython-i-only-can-call-the-pyini...", but it has no answers at all. Can you please share how do you prepare .pyd files to be used from LabVIEW? I created one by following the official Cython tutorial that can be found on that page: “https://cython.readthedocs.io/en/latest/src/quickstart/build.html”, but it didn’t work. I found the NI guide how to prepare .dll file using Visual Studio but it is not helpful in this case.

 

Kind thanks in advance

0 Kudos
Message 3 of 10
(3,134 Views)

There are many potential problems with this. A pyd file is indeed a sort of DLL but it also has runtime dependencies just as any other DLL. Typically that is at least the C runtime for the C compiler that was used to create the DLL. Depending on the setupfile that you used to create your pyd file, it invoked the according C compiler such as Microsoft Visual C, which of course needs to be installed. But each version of Visual C has its specific C runtime version that needs to be installed on any computer on which you try to load that dll/pyd file. Choosing another compiler such as MingW32 doesn't avoid that problem, it just requires you to install the according runtime library for the MingW32 version you had used.

 

Then there is the potential problem that this pyd file actually might call Python specific functions. These are provided by the PythonXX.dll file. This file is normally not installed in a way that the Windows DLL loader automatically would find it, since the Python.exe file is normally located in the same directory as that DLL and therefore will automatically link to it correctly, but for other programs, Windows won't be able to find the DLL.

 

So first problem is that you need to have the correct C Runtime library installed one every computer that you want to run this pyd file on. This C Runtime library is compiler specific and in most cases also version specific, meaning you need to install the C Runtime library version that matches the C compiler version used to create the pyd file.

 

Then you might have to help Windows to find the PythonXX.DLL file. This can happen by adding the according directory to the PATH environment variable. Some Python installers have an option to let it make this modification of your PATH environment variable at installation time, but this option is normally disabled by default as it is not needed to let Python itself run.

Rolf Kalbermatter
My Blog
Message 4 of 10
(3,120 Views)

I am new to labview and I am trying to call/load a .pyd file than controls a piece of test equipment that I normally control with Python.  A customer wants to use labview for the test equipment and specifically doesn't want to load Python on their computers.  

 

I downloaded labview (trial) and started out with loading a DLL...

I am stuck right away because the form to select Source Files is greyed out and wont let me open,

martin_2024_0-1727283145011.png

Information Panel,

martin_2024_1-1727283186606.png

 

Maybe this is not the flow to create an instrument with a DLL/pyd...

 

I also tried to import DLL,

martin_2024_0-1727283985886.png

 

0 Kudos
Message 5 of 10
(811 Views)

Hi martin,

 


@martin_2024 wrote:

I am new to labview …

I downloaded labview (trial) and started out with loading a DLL...

I am stuck right away because the form to select Source Files is greyed out and wont let me open,


No, you didn't started to "load a DLL". Instead you tried to create a DLL from (non-existing) LabVIEW code…

 


@martin_2024 wrote:

I also tried to import DLL,


Again you failed to "call a DLL function". The ImportWizard is only useful when you know a lot about the DLL…

 

Why don't you use the CLFN (CallLibraryFunction node)?

 

To summarize: when you are "new to LabVIEW" you should ot start with calling DLL functions. Learn LabVIEW basics first…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(791 Views)

Hi GerdW,

Thank you for the hint! Some progress made.

martin_2024_0-1727293362891.png

 

 

It would seem that my toolchain (Nuitka) doesn't expose the functions in the pyd file, so only one "init" function is found, whereas I have 3 other test functions in the original Python.  But I will keep researching and testing.

 

Back in the early 90s I went on a labview training course when the company I was working for decided to implement it.  But I haven't used it since... the ecosystem is massive now.  And navigating the SW tools... a lot to take in.

 

I have to either decide to write a real (normal) C/C++ DLL or try and coax my existing Python code to work.  Writing the DLL will take 4-8 weeks... Something I would very much like to avoid.  Using Cython to create the pyd might be the other option...

0 Kudos
Message 7 of 10
(783 Views)

Most likely you implemented a Python class and then only the init class instantiation function is exported. But class method access is always proprietary to the compiler. You can’t even generally interface to a C++ DLL from a different C++ compiler than what was used to create the DLL, not to talk about different object oriented languages.

 

I would strongly suspect that implementing the code in LabVIEW would almost certainly not take longer than doing the same in C(++), unless you are one mighty C(++) programmer who churns out fully perfect C(++) at several 1000 lines per hour!

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 10
(746 Views)

I agree with you re implementing anything in anything will be faster that writing something in C++...

 

Unfortunately my hardware is custom and streams a lot of data very fast to the PC for processing, and thus I need something like Python and C to handle it.

 

I am trying out Labview's Python support, despite my client saying they don't want that type of solution... if this python method is made simple enough, perhaps they change their mind. 

0 Kudos
Message 9 of 10
(713 Views)

If Python is fast enough, LabVIEW can do it too. Even with the next version of Python which still needs to get released, can a well written LabVIEW program run circles around any Python application!

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 10
(705 Views)