Python ignores LD_LIBRARY_PATH in openSUSE

There is an unexpected behavior of python in openSUSE (at least Leap 42.3 and Leap 15.1).
I am going to use a python module that needs to load external libraries (pyroot).
Normally, according to hints on the internet, a path to external libraries is set using LD_LIBRARY_PATH, but in openSUSE python does not try to look for libraries in the folders specified by LD_LIBRARY_PATH at all. I have tried the same for Ubuntu, and it worked as expected. Thus, I suppose it is a SUSE-related problem.
What should I do to fix this issue?
In my case the module and all related libraries are located in /usr/local/root/lib.
Here are some logs:


username@linux-jml8:~> python -c "import ROOT"
Traceback (most recent call last):
  File "<string>", 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


username@linux-jml8:~> ls /usr/local/root/lib/ROOT.py
/usr/local/root/lib/ROOT.py
username@linux-jml8:~> ls /usr/local/root/lib/libMathCore.so
/usr/local/root/lib/libMathCore.so
username@linux-jml8:~> echo $LD_LIBRARY_PATH
:/usr/local/root/lib
username@linux-jml8:~> echo $PYTHONPATH
/usr/local/root/lib


username@linux-jml8:~> strace python -c 'import ROOT' |& grep libMathCore.so
openat(AT_FDCWD, "/lib64/tls/haswell/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/tls/haswell/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/tls/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/tls/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/haswell/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/haswell/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/tls/haswell/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/tls/haswell/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/tls/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/tls/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/haswell/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/haswell/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/x86_64/libMathCore.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/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

As you can see, python does not try to check /usr/local/root/lib for the library, even though it is explicitly stated in LD_LIBRARY_PATH.

You are probably misunderstanding how it all works.

As far as I know, a running program (such as python) just asks the system to load the library module. It is the system that looks at LD_LIBRARY_PATH.

However, the path can also be preset at compile time with compiler options or by setting LD_RUN_PATH. And that’s possibly what happened here.

AppArmor settings may be blocking
https://doc.opensuse.org/documentation/leap/security/single-html/book.security/index.html#sec.apparmor.profiles.exec.m
https://doc.opensuse.org/documentation/leap/security/single-html/book.security/index.html#sec.apparmor.profiles.exec.variables

Or, not sure but you may need to explicitly import your ROOT environment with a fixed path.
This use of importing custom environmentals is something I haven’t had to do often so don’t have much experience with it, maybe a review of python environmentals and how to set may be required here…

TSU

a running program (such as python) just asks the system to load the library module

Python interpreter uses its own system of loading libraries. Other programs have no problems with loading the libraries in question.

the path can also be preset at compile time with compiler options or by setting LD_RUN_PATH

I would definitely prefer to avoid recompiling python and dozens of dependent packages from sources.

AppArmor settings may be blocking

Disabling AppArmor didn’t help.

maybe a review of python environmentals and how to set may be required here

Even after an extensive search on the internet, the only way I was able to find for python to import a custom path for libraries was via LD_LIBRARY_PATH, that is ignored in openSUSE.

I don’t know enough about what you are doing to try repeating this. However, I note in your first post:


username@linux-jml8:~> ls /usr/local/root/lib/libMathCore.so
/usr/local/root/lib/libMathCore.so
username@linux-jml8:~> echo $LD_LIBRARY_PATH
:/usr/local/root/lib

Additionally, you should check:


file /usr/local/root/lib/libMathCore.so

to make sure that this is the appropriate type of file;

and


printenv LD_LIBRARY_PATH

to make sure that this is in your environment, and not just a local shell variable.

My references to python environmental paths didn’t actually mean to rely on system library paths like LD_LIBRARY_PATH, and wasn’t meant to be related to anything related to your basic python install (although through virtualenv is a recommended way), I meant simply importing modules for your specific app.

Am having problems locating a really good resource describing what I mean, but the following is close
https://folk.uio.no/jeanra/Informatics/SettingUpPythonPaths.html

But on the topic of using virtualenv, it’s something you might consider seriously… It’s the standard way Python developers install, maintain and deploy multiple versions of Python side by side on the same system, and of course when you do this you have to closely configure all the libraries and environmental variables to keep them separate.

I don’t see any SUSE/openSUSE documentation on this important subject, but this is one of many generic articles posted online…
https://kb.iu.edu/d/aonm

TSU