python-build-standalone: Latest changes to statically link `libpython` breaks usage of packages like `python-mscl`
Hello!
I noticed that after upgrading uv to 0.7.6 and reinstalling python (uv python install --reinstall), the import of a package like python-mscl breaks. Here’s a traceback:
Python 3.13.3 (main, May 17 2025, 13:34:03) [GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from python_mscl import mscl
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
from python_mscl import mscl
File "/home/pi/AirbrakesV2/.venv/lib/python3.13/site-packages/python_mscl/__init__.py", line 1, in <module>
from . import mscl
File "/home/pi/AirbrakesV2/.venv/lib/python3.13/site-packages/python_mscl/mscl.py", line 13, in <module>
from . import _mscl
ImportError: libpython3.13.so.1.0: cannot open shared object file: No such file or directory
Since I’m also the maintainer of python-mscl, I can give some more insight on how that package works:
My package is just a wrapper around https://github.com/LORD-MicroStrain/MSCL, aiming to simplify the installation procedure of the library, which is a little convoluted and not easy to setup on new machines - link.
So I am essentially just bundling the .so and .py files they provide into a package for every python version and architecture. And this just works on import, since it can find the .so and .py files in the same directory.
So I’m not sure if there’s something wrong with how I’m packaging this library, and I have to correct it somehow, or if this was a problem with how my python was built. Since this happened immediately after reinstalling my python, and I saw the release note which mentioned this change, I thought I should open an issue to seek some clarification.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 26 (2 by maintainers)
Commits related to this issue
- Restore an rpath to bin/python3 to fix #619 Even though the Python interpreter no longer needs libpython3.x.so, it turns out some extension modules (incorrectly) do, and miraculously, allowing them t... — committed to geofft/python-build-standalone by geofft 2 years ago
- Add an rpath to bin/python3 on glibc platforms to fix #619 Even though the Python interpreter no longer needs libpython3.x.so, it turns out some extension modules (incorrectly) do, and miraculously, ... — committed to geofft/python-build-standalone by geofft 2 years ago
- Add an rpath to bin/python3 on glibc platforms to fix #619 (#621) Even though the Python interpreter no longer needs libpython3.x.so, it turns out some extension modules (incorrectly) do, and miracul... — committed to loong64/python-build-standalone by geofft a year ago
- Sync latest Python releases Pick up python-build-standalone 20250522, in particular to fix astral-sh/python-build-standalone#619 — committed to geofft/uv by geofft a year ago
- Sync latest Python releases (#13593) Pick up python-build-standalone 20250522, in particular to fix astral-sh/python-build-standalone#619 — committed to astral-sh/uv by geofft a year ago
- Sync latest Python releases (#13593) Pick up python-build-standalone 20250522, in particular to fix astral-sh/python-build-standalone#619 — committed to astral-sh/uv by geofft a year ago
- Revert "Add an rpath to bin/python3 on glibc platforms to fix #619 (#621)" This reverts commit 482a9bc818a81a236397a603e5fd169187aaabbe. — committed to astral-sh/python-build-standalone by geofft a year ago
We just ran into this as well in https://github.com/rapidsai/dask-upstream-testing/issues/56.
@geofft I think it would probably be helpful to give a bit of lead time to projects to adapt to this. I’m guessing that many projects have been linking to libpython without recognizing the pitfalls of that. I am not entirely sure how we are hitting this in our case since we run auditwheel on our wheels, so I’ll have to take another look later today and see if there are edge cases that auditwheel is letting through that might be exacerbating the frequency of this problem (or if we’re simply misusing it somehow). In general, including libpython linkage seems like an easy mistake to make. For projects using CMake to build against Python, though, it will require a bit of work since you will have to move away from a typical
target_link_libraries(... Python3::Python)to instead extract include dirs and only using those. That will be a nontrivial change for most people who are not regular CMake practitioners, so some grace period would be appreciate. I imagine Meson or Bazel builds will have similar issues.That being said, I do think it is a mistake. To respond to the first half of your comment:
Yes, I agree that other projects should likely be fixing this. libpython linkage is explicitly forbidden by the manylinux standard to support exactly this kind of use case if I understand correctly.
@harshil21 Yes, the correct solution is to avoid linking to libpython altogether. The GNU linker allows undefined symbols by default when building shared libraries, so simply not including libpython on the link line when building should be sufficient. The Python interpreter will load up all the missing symbols at runtime so your package should work without that linkage. In your case, it sounds like you are repackaging pre-built binaries. If that is the case, you can modify them with patchelf. Something like
patchelf --remove-needed libpython3.13.so.1.0 ${YOUR_LIBRARY_HERE}should do the trick.python-build-standalone 20250529, released earlier today, sets a
DT_RPATHinstead of aDT_RUNPATHso that it gets inherited properly to extension modules. I’ve tested thatpython-msclseems to work with it.As discussed above this does not help
ucxxbecause itsDT_RUNPATHsuppresses ourDT_RPATH. I’m going to close this issue for now, if it’s important to support existing versions ofucxxor similar wheels, I have some ideas for more invasive workarounds, let me know. (Also if this change still did not fix the more common case, please do yell!)This build is included in uv 0.7.9, released earlier today, so
uv self update && uv python install --reinstallshould get you going, CI should work, etc.Also, uv 0.7.8, released last Friday, rolled back to the python-build-standalone release before the static libpython changes, so things should have been fine for uv users since last Friday in fact. (Note this means that
ucxxwas fine on latest uv from last Friday to today but no longer is.)Oh, I think I see what’s wrong, I’m afraid this fix wasn’t quite correct. Thanks for reporting!
I’m going to take the opportunity to add some testing and be confident that the behavior is what we expect, so it’ll be a bit longer before we get releases out. In the meantime, the two workarounds above are still available: either use last week’s Python releases with
or potentially before importing the extension do
And I meant to say this earlier but thanks for your patience 😃
Here’s the output:
Thanks @geofft! I can confirm that the original example with
python_msclworks on my system with uv 0.7.7 (after auv self updateanduv python install 3.13 --reinstall.Our
ucxxlibrary is still hitting the same withuv run --python=3.13 --prerelease=allow --extra-index-url="https://pypi.anaconda.org/rapidsai-wheels-nightly/simple" --with "ucxx-cu12>=0.44.0a0,<0.45.0a0" python -c 'import ucxx'.However, I also see that with the python from conda-forge (but still using the wheel):
So I think at this point we can say things probably need to be fixed in ucxx rather than python-build-standalone.
Thanks for the explanation! You’re right, it did load my system’s:
This is a fascinating edge case indeed.
A workaround if you’re broken by this in the short term is
which will grab the versions of python-build-standalone that were current in the previous uv release, i.e., the most recent versions with a dynamic libpython, and unpack those.
If this starts causing significantly more breakage, we can revert (we can pretty quickly put out a new release of uv that reverts the python-build-standalone versions, so we go back to known-good builds). I am working through some options to let us roll forward, i.e., deliver an interpreter that statically links libpython but is still compatible with these sorts of existing extensions.
In particular, I think I know what’s going on with Debian/Ubuntu and conda-forge, which ship Pythons that are (like ours) statically linking libpython, and why the two libraries mentioned so far in this bug are fine in practice on those Pythons but not ours, ~which I’ll expand on in the next comment~ (actually I am not sure I have the details 100% right so I’m going to work on some code first 😃 ).
It looks like auditwheel is currently set up to ignore libpython linkage when checking for external dependencies. That’s a problem for us here because it means that projects that have been relying on auditwheel to enforce manylinux compliance have been getting a free pass on this particular violation. I opened https://github.com/pypa/auditwheel/issues/589 to discuss whether auditwheel’s behavior should be changed.
In the interim, my suggestion is that python-build-standalone roll back this change and give a bit of lead time to projects to update before bringing back the static linkage. My guess is that there are a large number of projects relying on auditwheel that assume they are doing the right thing, and some of them may not be.
I’m also not sure how this will play on other platforms where there has never been a standard like manylinux to codify this information since there were de facto realities imposed by the OS. Is it possible to have an OS X distribution without Python available? If not, and if pyenv and similar tools always produce environments with libpython.so, then prior to python-build-standalone there may have been no real environments where this was a problem.
We did some benchmarks prior to working on that change. It’s like 15-25%, though it’s platform dependent.