uv: [bug] Can't build Rust extensions via `pyo3` if using a `uv`-managed Python interpreter

When building the extension, the following error occurs (omitting the prefixes of some paths):

dyld[90807]: Library not loaded: /install/lib/libpython3.13.dylib
  Referenced from: <A73153CF-70A5-379B-B9D3-526153D8322F> repro/target/debug/deps/setup-29f3c899bfb488ef
  Reason: tried: '/install/lib/libpython3.13.dylib' (no such file), 'repro/target/debug/deps/libpython3.13.dylib' (no such file), 'repro/target/debug/libpython3.13.dylib' (no such file), '.rustup/toolchains/stable-aarch64-
apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpython3.13.dylib' (no such file), '.rustup/toolchains/stable-aarch64-apple-darwin/lib/libpython3.13.dylib' (no such file), '/Users/luca/lib/libpyt
hon3.13.dylib' (no such file), '/usr/local/lib/libpython3.13.dylib' (no such file), '/usr/lib/libpython3.13.dylib' (no such file, not in dyld cache)
error: test failed, to rerun pass `--lib

This is on macOS, using the latest Rust toolchain and uv build. I uploaded a reproduction repository to help with the investigation.

I originally suspected this to be an issue with sysconfig, but it appears to be configured correctly:

Image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 30 (30 by maintainers)

Commits related to this issue

Most upvoted comments

Happy to give it a try—any pointer as to where I should be looking at for the installation phase?

tada

❯ install_name_tool -id /Users/zb/.local/share/uv/python/cpython-3.12.6-macos-aarch64-none/lib/libpython3.12.dylib /Users/zb/.local/share/uv/python/cpython-3.12.6-macos-aarch64-none/lib/libpython3.12.dylib

❯ otool -L /Users/zb/.local/share/uv/python/cpython-3.12.6-macos-aarch64-none/lib/libpython3.12.dylib
/Users/zb/.local/share/uv/python/cpython-3.12.6-macos-aarch64-none/lib/libpython3.12.dylib:
	/Users/zb/.local/share/uv/python/cpython-3.12.6-macos-aarch64-none/lib/libpython3.12.dylib (compatibility version 3.12.0, current version 3.12.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.61.1)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libpanel.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2202.0.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
	/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 1296.60.3)
	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2487.30.104)
	/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 64.0.0)
	/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1774.2.3)
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1226.0.0)
	/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 2202.0.0)
	/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 170.0.0)
	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 24.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.12)

❯ cargo clean
     Removed 313 files, 72.4MiB total
❯ PYO3_PYTHON="$(uv python find 3.12)" cargo t
   Compiling target-lexicon v0.12.16
   Compiling once_cell v1.20.2
   Compiling proc-macro2 v1.0.93
   Compiling unicode-ident v1.0.14
   Compiling autocfg v1.4.0
   Compiling libc v0.2.169
   Compiling heck v0.5.0
   Compiling indoc v2.0.5
   Compiling cfg-if v1.0.0
   Compiling unindent v0.2.3
   Compiling memoffset v0.9.1
   Compiling pyo3-build-config v0.23.4
   Compiling quote v1.0.38
   Compiling syn v2.0.96
   Compiling pyo3-ffi v0.23.4
   Compiling pyo3-macros-backend v0.23.4
   Compiling pyo3 v0.23.4
   Compiling pyo3-macros v0.23.4
   Compiling setup v0.1.0 (/Users/zb/workspace/uv-repro-install-lib)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 3.77s
     Running unittests src/lib.rs (target/debug/deps/setup-29f3c899bfb488ef)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

I guess we should try to do that at install time.

The rustc-link-search caveat seems worth pursing. I tried using the target directory though — no dice. Maybe it needs to be in a specific spot?

I’d have to be target/debug (for a debug build). The top-level target directory it’s indeed not in the search path by default.