[Python] cargo build with pyo3 uses a weird /install prefix for lib

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I have tried to set either PYO3_CROSS_LIB_DIR or PYO3_PYTHON, both from terminal or in my build.rs but I keep having this /install as prefix everywhere and consequently my bin is not working.

    I'm using

    • pyenv for managing python versions
    • mac os 15.3.2 on Apple M2.
    • a venv managed by uv.
    • pyo3 = { version = "0.23.4" }

    my builds.rs looks like

    use dotenvy::dotenv_override;
    use std::env;

    fn main() {
    if let Err(err) = dotenv_override() {
    eprintln!("Warning: Failed to load .env file: {err}");
    }

    // Build time dependencies
    if let Ok(lib_path) = env::var("LIBRARY_PATH") {
    println!("cargo:rustc-link-search={lib_path}");
    println!("cargo:rerun-if-env-changed=LIBRARY_PATH");
    }

    // Link time dependencies
    if let Ok(ld_library_path) = env::var("LD_LIBRARY_PATH") {
    println!("cargo:rustc-link-arg=-Wl,-rpath,{ld_library_path}");
    println!("cargo:rerun-if-env-changed=LD_LIBRARY_PATH");
    }

    if let Ok(dyld_library_path) = env::var("DYLD_LIBRARY_PATH") {
    println!("cargo:rustc-link-arg=-Wl,-rpath,{dyld_library_path}");
    println!("cargo:rerun-if-env-changed=DYLD_LIBRARY_PATH");
    }
    }


    when I run PYO3_PRINT_CONFIG=1 cargo b I see

    -- PYO3_PRINT_CONFIG=1 is set, printing configuration and halting compile --
    implementation=CPython
    version=3.10
    shared=true
    abi3=false
    lib_name=python3.10
    lib_dir=/install/lib
    executable=/Users/clementwalter/Documents/kkrt-labs/keth/.venv/bin/python
    pointer_width=64
    build_flags=
    python_framework_prefix=
    suppress_build_script_link_lines=false


    so here I already see this /install and I don't know where it comes from.

    once built, using otool I see

    $ otool -L target/release/keth-run
    target/release/keth-run:
    /install/lib/libpython3.10.dylib (compatibility version 3.10.0, current version 3.10.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)


    if then I try to run, it fails

    dyld[41034]: Library not loaded: /install/lib/libpython3.10.dylib
    Referenced from: <7D8217ED-521B-3870-B777-1DAFA99B7940> /Users/clementwalter/Documents/kkrt-labs/keth/target/debug/keth-run
    Reason: tried: '/install/lib/libpython3.10.dylib' (no such file)


    if I export the DYLD path

    export DYLD_LIBRARY_PATH=$HOME/.local/share/uv/python/cpython-3.10.15-macos-aarch64-none/lib


    it actually starts but raises and again I see all these /install prefixes

    Could not find platform independent libraries <prefix>
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    Python path configuration:
    PYTHONHOME = (not set)
    PYTHONPATH = (not set)
    program name = 'python3'
    isolated = 0
    environment = 1
    user site = 1
    import site = 1
    sys._base_executable = '/Users/clementwalter/Documents/kkrt-labs/keth/target/debug/keth-run'
    sys.base_prefix = '/install'
    sys.base_exec_prefix = '/install'
    sys.platlibdir = 'lib'
    sys.executable = '/Users/clementwalter/Documents/kkrt-labs/keth/target/debug/keth-run'
    sys.prefix = '/install'
    sys.exec_prefix = '/install'
    sys.path = [
    '/install/lib/python310.zip',
    '/install/lib/python3.10',
    '/install/lib/lib-dynload',
    ]
    Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
    Python runtime state: core initialized
    ModuleNotFoundError: No module named 'encodings'

    Continue reading...

Compartilhe esta Página