Skip to content

libpython of a relocated Python is not found, as only sysconfig LIBDIR is looked at #76

Open

Description

@morisil

With the fix for #54, PythonEnvironment finds the libpython to preload (and to name in the LD_LIBRARY_PATH advice) only through sysconfig.get_config_var('LIBDIR').
A Python whose prefix moved since it was built reports a stale LIBDIR: a python-build-standalone not patched by uv reports /install/lib, and any relocated prefix its old path.
Then nothing is preloaded and no advice is added to the startup error — the same failure as on main before #54.

Possible fix: fall back to sys.base_prefix/lib (and LDLIBRARY / libpython{LDVERSION}.so.1.0) when LIBDIR/INSTSONAME does not exist.

Found during the review of the fix for #54.

Activity

  1. morisil commented on Nov 13, 2026

    @morisil
    MemberAuthor

    Status of the automated fix run: blocked after 3 review rounds (the cap), on branch issue-76-relocated-libpython (stacked on #78), no PR.

    The fix works for the issue's case — a relocated Python whose LIBDIR reports /install/lib gets its libpython preloaded from <sys.base_exec_prefix>/lib, proven end to end on uv CPython 3.10 and 3.13 (the test checks the mapped library in /proc/self/maps) — but the last review found two regressions against #78:

    1. A Python started through a symlinked bin directory (e.g. ln -s <uv-python>/bin a1/bin) reports sys.base_exec_prefix as the compiled-in /install while sys.base_prefix is right; uv's patched build exec_prefix makes it count as relocated, so the remap goes to /install/lib and finds nothing, where Load the libpython of a Python outside the system library directories #78 found LIBDIR as it is.
      Direction: try the remapping against sys.base_prefix too, and fall back to LIBDIR as it is when it exists and the build prefix is the same file as a base prefix — or, on Linux, let the probe report the libpython it has actually mapped (/proc/self/maps), which needs no prefix arithmetic at all (not for Debian's statically linked /usr/bin/python3, which maps none; the venv's Python is what is probed, though).
    2. README: the advice for a library not found lost the pointer to the LIBDIR of sysconfig (the startup error names no directory then); keep it, noting it is stale for a moved Python.

    Minor: normalize each prefix once; the static half of the "other than its soname" test returns before any lookup; the probe test computes its expectation with the same private sysconfig._get_sysconfigdata_name() expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions