PyROOT can't find ROOT libraries

I’ve just started to learn python, and I want to try out PyROOT. I’ve encountered the problem that when I try to launch it from the python shell, it can’t locate the ROOT libraries. All the hints I’ve found on the internet recommend to set up LD_LIBRARY_PATH, but in my case it has already been set up, it can be seen from the logs below.
How can I make the python shell to find the libraries?

<user>@<PC>:/usr/local/root/lib> echo $LD_LIBRARY_PATH
/lib64:/usr/lib64:/usr/local/lib64:/usr/local/cuda/lib64:/usr/local/root/lib:.
<user>@<PC>:/usr/local/root/lib> python3
Python 3.4.6 (default, Mar 22 2017, 12:26:13) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import gROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/root/lib/ROOT.py", line 24, in <module>
    import cppyy
  File "/usr/local/root/lib/cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: libMathCore.so: cannot open shared object file: No such file or directory

ROOT Version: 6.12/04
Platform: Linux openSUSE 42.3
Compiler: g++ 4.8.5


Hi @Dmitry_Tsirkov, you need to set both $PYTHONPATH and $LD_LIBRARY_PATH to point to $ROOTSYS/lib. The message above may be because libMathCore.so may not be in your LD_LIBRARY_PATH.

libMathCore.so is, of course, in LD_LIBRARY_PATH (see logs below).
Cling interpreter runs and successfully loads ROOT libraries. C++ applications linked against ROOT compile and run as well.
I suppose it is some problem with python configuration, since I’ve been using ROOT with C++ for years and never experienced any problems with libraries.
PYTHONPATH is set to $ROOTSYS/lib, anyway.

<user>@<PC>:~> echo $PYTHONPATH
/usr/local/root/lib
<user>@<PC>:~> echo $LD_LIBRARY_PATH
/lib64:/usr/lib64:/usr/local/lib64:/usr/local/cuda/lib64:/usr/local/root/lib:.
<user>@<PC>:~> locate libMathCore.so
/usr/local/root/lib/libMathCore.so

locate can have a stale cache, so the file may not be really there, or may be truncated. I cannot think of other reason for the file not found otherwise.

It is there, and it works with (for example) Cling.

<user>@<PC>:~> ls -l /usr/local/root/lib/libMathCore.so
-rwxr-xr-x 1 root root 12860272 фев 13 15:52 /usr/local/root/lib/libMathCore.so
<user>@<PC>:~> root -l
root [0] gSystem->Load("libMathCore.so");
root [1]

Run the following to see which directories are considered to find libMathCore.so:

strace python -c 'import ROOT; ROOT.kRed' |& grep libMathCore.so

Note that gSystem::Load does more than just rely on LD_LIBRARY_PATH, so it’s perfectly possible that your envar has some problem, e.g. that it contains (unprintable) non-ascii characters. If so, this may help:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH

I’m not sure why, but looks like my python installation ignores LD_LIBRARY_PATH for some reason and searches only inside /lib64 and /usr/lib64

<user>@<PC>:~> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
<user>@<PC>:~> echo $LD_LIBRARY_PATH
/lib64:/usr/lib64:/usr/local/lib64:/usr/local/cuda/lib64:/usr/local/root/lib:.
<user>@<PC>:~> strace python3 -c 'import ROOT; ROOT.kRed' |& grep libMathCore.so
open("/lib64/tls/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/tls/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
ImportError: libMathCore.so: cannot open shared object file: No such file or directory

On Mac, the system python is doctored to ignore LD_LIBRARY_PATH, for security reasons. Perhaps SuSE went down the same road?

If true, then one option would be to install your own python and use that.

Thanks for the debugging hints. Looks like I should proceed to openSUSE forums with the issues of python installation.

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