[Python] how can I add new LD path in python?

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    import ctypes.util
    import importlib.util
    import os
    lib_dir=... # some local installed clibs
    os.environ["LD_LIBRARY_PATH"] = lib_dir + ":" + os.environ.get("LD_LIBRARY_PATH", "")
    os.environ["PATH"] = lib_dir + ":" + os.environ.get("PATH", "")

    import ctypes

    print(ctypes.util.find_library("xx"))
    libxx = ctypes.cdll.LoadLibrary("libxx.so")
    print(get_library_path(libxx))


    Here the environ change does not affect the ctypes at all, unless I add them to LD path before I start the python interpreter, this is very annoying, basically prevent us to add new libs during instance running.

    In windows there is add_dll_directory, but how can I do this in linux?

    Continue reading...

Compartilhe esta Página