Skip to content

Commit

Permalink
Improve libpython search with python's sysconfig INSTSONAME
Browse files Browse the repository at this point in the history
This should be considered a partial improvement related to jpy-consortium#75.

A fuller solution might involve listing which shared objects were actually loaded via [`dl_iterate_phdr`](https://man7.org/linux/man-pages/man3/dl_iterate_phdr.3.html).

python/cpython#119349
  • Loading branch information
devinrsmith committed Jan 6, 2025
1 parent 042d510 commit 739daad
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions jpyutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ def _find_python_dll_file(fail=False):
logger.debug("Potential Python shared library search dirs: %s" % repr(search_dirs))

# Prepare list of possible library file names
# Prefer "Install .so name" as first candidate for file_names
instsoname = sysconfig.get_config_var("INSTSONAME")
file_names = [ instsoname ] if instsoname else []

# account for Python debug builds

Expand All @@ -346,14 +349,14 @@ def _find_python_dll_file(fail=False):

if platform.system() == 'Windows':
versions = (vmaj + vmin, vmaj, vmaj + vmin + dll_suffix, '')
file_names = ['python' + v + '.dll' for v in versions]
file_names += ['python' + v + '.dll' for v in versions]
elif platform.system() == 'Darwin':
versions = (vmaj + "." + vmin, vmaj, vmaj + "." + vmin + dll_suffix, '')
file_names = ['libpython' + v + '.dylib' for v in versions] + \
['libpython' + v + '.so' for v in versions]
file_names += ['libpython' + v + '.dylib' for v in versions]
file_names += ['libpython' + v + '.so' for v in versions]
else:
versions = (vmaj + "." + vmin, vmaj, vmaj + "." + vmin + dll_suffix, '')
file_names = ['libpython' + v + '.so' for v in versions]
file_names += ['libpython' + v + '.so' for v in versions]

logger.debug("Potential Python shared library file names: %s" % repr(file_names))

Expand Down

0 comments on commit 739daad

Please sign in to comment.