Load c++ shared library in PyRoot

Hello guys, I am here asking a question about how python and ROOT are linked.

In root cli, we can load one library easily(Contains TObject class).
Then we can use those self defined class, which inherit from TObject.

gSystem->Load(“mydir/mylib.so”);

While in PyROOT, we can import root class with ROOT.gPad, ROOT.TH1F, etc.

import ROOT

However, how can I load those self defined libraries, for later we can use the same way as ROOT.myclass.
I tried

ROOT.gROOT.Macro( os.path.expanduser( ‘~/rootlogon.C’ ) );
within rootlogon.C,
gSystem->Load(“mydir/mylib.so”);

The mylib truely loaded from the printed information, however, I have no way to call it in python.

I think my question can be answered if someone can share some knowledge on how these 2 libs are generated.
libROOTTPython.so
libROOTPythonizations3_6.so

Thanks.

_ROOT Version:6.22
_Platform:centos7
_Compiler:gcc 9

Hi,

Please have a look at:

Cheers,
Enric

Thanks, it is solved by.

import ROOT
ROOT.gInterpreter.AddIncludePath(‘./include’)
ROOT.gSystem.Load("./mylib.so’)

Hi,
I am trying the same

ROOT.gInterpreter.AddIncludePath(’/path/to/my/library/’)
ROOT.gSystem.Load("./libAnalysisTreeBase.so")

but I get the error

cling::DynamicLibraryManager::loadLibrary(): libCore.so.6.20: cannot open shared object file: No such file or directory

Hi,
This can indicate a problem with your environment, how did you install ROOT and set your environment?

Hi,
The most probable problem could be that you are not setting environment correctly.
Please set the proper $LD_LIBRARY_PATH before run ipython, or jupyter.
or in the first lines set this : ```
os.environ[“LD_LIBRARY_PATH”]

Hope this could help you.

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