59
59
import ctypes
60
60
import pathlib
61
61
import functools
62
- import importlib .resources
62
+ try :
63
+ # Python < 3.9
64
+ import importlib_resources
65
+ except ImportError :
66
+ import importlib .resources as importlib_resources
63
67
from typing import (
64
68
cast ,
65
69
Any ,
79
83
# Load the library
80
84
def load_shared_library (module_name : str , lib_base_name : str ):
81
85
# Construct the paths to the possible shared library names
82
- base_path = pathlib .Path (__file__ ).parent .resolve ()
86
+ base_path = pathlib .Path (__file__ ).parent .resolve () / "lib"
83
87
# Searching for the library in the current directory under the name "libggml" (default name
84
88
# for ggml) and "ggml" (default name for this repo)
85
89
lib_names : List [str ] = [
@@ -92,7 +96,8 @@ def load_shared_library(module_name: str, lib_base_name: str):
92
96
93
97
for lib_name in lib_names :
94
98
try :
95
- with importlib .resources .path (module_name , lib_name ) as p :
99
+ with importlib_resources .as_file (importlib_resources .files (module_name ).joinpath ("lib" , lib_name )) as p : # type: ignore
100
+ p = cast (pathlib .Path , p )
96
101
if os .path .exists (p ):
97
102
path = p
98
103
break
@@ -107,6 +112,7 @@ def load_shared_library(module_name: str, lib_base_name: str):
107
112
cdll_args = dict () # type: ignore
108
113
# Add the library directory to the DLL search path on Windows (if needed)
109
114
if sys .platform == "win32" and sys .version_info >= (3 , 8 ):
115
+ os .environ ["PATH" ] = str (base_path ) + os .pathsep + os .environ ["PATH" ]
110
116
os .add_dll_directory (str (base_path ))
111
117
cdll_args ["winmode" ] = 0
112
118
@@ -7752,7 +7758,7 @@ class gguf_init_params(ctypes.Structure):
7752
7758
7753
7759
if TYPE_CHECKING :
7754
7760
no_alloc : bool
7755
- ctx : ggml_context_p
7761
+ ctx : CtypesPointer [ ggml_context_p ]
7756
7762
7757
7763
_fields_ = [
7758
7764
("no_alloc" , ctypes .c_bool ),
0 commit comments