ktbarrett / find_libpython

Finds the libpython associated with the current Python environment, wherever it may be hiding.
MIT License
14 stars 7 forks source link

Find libraries with SONAME #35

Closed imphil closed 2 years ago

imphil commented 2 years ago

find_libpython does not find libpython currently if only a shared object with a SONAME exists, i.e. only "libpython3.8.so.1.0", but no "libpython3.8.so". That's the case in RHEL8 with the Red Hat python38 package installed, so a rather common scenario.

Here's how it looks on my RHEL8 machine:

$ ls -l /usr/lib64/libpython3*
lrwxrwxrwx. 1 root root      20 14. Jun 18:56 /usr/lib64/libpython3.6m.so -> libpython3.6m.so.1.0
-rwxr-xr-x. 1 root root 3285672 14. Jun 18:57 /usr/lib64/libpython3.6m.so.1.0
-rwxr-xr-x. 1 root root 3714264 16. Sep 2021  /usr/lib64/libpython3.8.so.1.0
-rwxr-xr-x. 1 root root    6888 14. Jun 18:57 /usr/lib64/libpython3.so

See also https://github.com/cocotb/cocotb/issues/3097

imphil commented 2 years ago

Looking at the code I guess we could either attach the soname to the suffix and see if that file exists (I don't think anything other than "1.0" exists), or use the config var INSTSONAME. I wonder why that wasn't used before? @ktbarrett you have the best overview on the options you tried and the mess surrounding it, so maybe you could have a look?

As data point, here's what I get on RHEL8, which in both cases is exactly the right library.

python3.8 -c 'from distutils.sysconfig import get_config_var; print("%s/%s" % (get_config_var("LIBDIR"), get_config_var("INSTSONAME")))'
/usr/lib64/libpython3.8.so.1.0

python3.6 -c 'from distutils.sysconfig import get_config_var; print("%s/%s" % (get_config_var("LIBDIR"), get_config_var("INSTSONAME")))'
/usr/lib64/libpython3.6m.so.1.0
ktbarrett commented 2 years ago

Looks like something may have changed recently? https://github.com/ktbarrett/find_libpython/actions was passing RHEL8, then started failing. And the action stopped working for some reason...

Seems like a good way to reliably find the library on some systems, not sure why it wasn't used in the original code. Could you open a PR to add it somewhere?

imphil commented 2 years ago

Looks like something may have changed recently? ktbarrett/find_libpython/actions was passing RHEL8, then started failing. And the action stopped working for some reason...

The action only tested the system Python (3.6), not the additional Python versions available on RHEL7 and 8 throgh SCLs (https://github.com/ktbarrett/find_libpython/blob/master/.github/workflows/tests.yml#L118). Python 3.6 as shipped with RHEL8 has the symlinks from .so.1.0 -> .so in place, only the AppStream versions don't.