Issue with using ROOT in a dynamic library with ctypes in Python

I have created a dynamic library loading a ROOT file. The mex-version of this function works fine in MATLAB without any issues so all the ROOT libraries are found on PATH. However, when using the DLL with ctypes in Python I get the following error:
c_lib = ctypes.CDLL(libname) *** FileNotFoundError: Could not find module '\path\to\libRoot.dll' (or one of its dependencies). Try using the full path with constructor syntax.
However, if I put import ROOT before it, everything works fine, more specifically it is the import of libROOTPythonizations that fixes the issue. Since PyROOT requires specific Python version (when using the binaries) I’d rather avoid the use of PyROOT. Is there a way to get the library load working without the use of PyROOT?

ROOT Version: 6.30/04
Platform: Windows 10 x64
Compiler: Visual Studio 19.39.33519


Thanks for the interesting post. I add in the loop @bellenot , who might be able to help out better than me.

In the meantime, may I ask whether your libRoot.dll path is in the PATH environment variable to allow the linker to find it at runtime?


Can you be more precise? There is no libROOT.dll in the ROOT binaries…

libRoot.dll is my own library that I use to load a ROOT file in Python. Also to further clarify, the library loads fine if I either add import ROOT (or as I mentioned it is specifically the import of libROOTPythonizations3_8.pyd that helps) or simply remove all ROOT related code. I also have a MATLAB mex-file based on the same code that works without any issues, the only difference is the function that calls the ROOT-related function.

The question is why the import of libROOTPythonizations3_8.pyd is required to make my libRoot.dll load fine with ctypes? And is there some way to avoid it?

No idea, I’ll have to investigate…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.