From 92f1ccf7ab49ab874593d71cb06e4416d114b4e3 Mon Sep 17 00:00:00 2001 From: bgmt Date: Fri, 20 Feb 2026 21:18:37 -0500 Subject: [PATCH 1/3] search system paths for shared libraries --- llama_cpp/_ctypes_extensions.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/llama_cpp/_ctypes_extensions.py b/llama_cpp/_ctypes_extensions.py index 619a6a555..cd8a182ca 100644 --- a/llama_cpp/_ctypes_extensions.py +++ b/llama_cpp/_ctypes_extensions.py @@ -95,10 +95,19 @@ def load_shared_library(lib_base_name: str, base_paths: Union[pathlib.Path, list errors = [] - # Try to load the shared library, handling potential errors + # First, try to find an available library through the system + lib_path = ctypes.util.find_library(lib_base_name) + if lib_path: + try: + return ctypes.CDLL(lib_path, **cdll_args) + except Exception as e: + pass + + # Then fallback to manually checking the list of paths. for base_path in base_paths: for lib_name in lib_names: - lib_path = base_path / lib_name + lib_path = pathlib.Path(base_path) / lib_name + if lib_path.exists(): try: return ctypes.CDLL(str(lib_path), **cdll_args) From 9a33454260f1f177b7f0694d3fc7ed8ee672b351 Mon Sep 17 00:00:00 2001 From: bgmt Date: Sat, 21 Feb 2026 06:57:23 -0500 Subject: [PATCH 2/3] fix import --- llama_cpp/_ctypes_extensions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llama_cpp/_ctypes_extensions.py b/llama_cpp/_ctypes_extensions.py index cd8a182ca..0e5153e3a 100644 --- a/llama_cpp/_ctypes_extensions.py +++ b/llama_cpp/_ctypes_extensions.py @@ -5,7 +5,7 @@ import ctypes import functools import pathlib - +from ctypes.util import find_library from typing import ( Any, Callable, @@ -96,7 +96,7 @@ def load_shared_library(lib_base_name: str, base_paths: Union[pathlib.Path, list errors = [] # First, try to find an available library through the system - lib_path = ctypes.util.find_library(lib_base_name) + lib_path = find_library(lib_base_name) if lib_path: try: return ctypes.CDLL(lib_path, **cdll_args) From 1619c16cd542731825352824c0374fd40fc74e44 Mon Sep 17 00:00:00 2001 From: bgmt Date: Sat, 21 Feb 2026 07:26:31 -0500 Subject: [PATCH 3/3] append errors --- llama_cpp/_ctypes_extensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama_cpp/_ctypes_extensions.py b/llama_cpp/_ctypes_extensions.py index 0e5153e3a..a8936fa2b 100644 --- a/llama_cpp/_ctypes_extensions.py +++ b/llama_cpp/_ctypes_extensions.py @@ -101,7 +101,7 @@ def load_shared_library(lib_base_name: str, base_paths: Union[pathlib.Path, list try: return ctypes.CDLL(lib_path, **cdll_args) except Exception as e: - pass + errors.append(f"{lib_path}: {e}") # Then fallback to manually checking the list of paths. for base_path in base_paths: