diff --git a/python/kcl_lib/api/service.py b/python/kcl_lib/api/service.py index 38c8930f..8104f217 100644 --- a/python/kcl_lib/api/service.py +++ b/python/kcl_lib/api/service.py @@ -109,7 +109,14 @@ def __init__(self): install_kclvm(env_install_path) self.lib = ctypes.CDLL(os.path.join(env_install_path, lib_full_name())) else: - self.lib = ctypes.CDLL(os.path.join(lib_path(), lib_full_name())) + # Set the kcl lib and open it. + path = lib_path() + path_env = os.environ.get("PATH", "") + bin_path_str = str(path) + new_path_env = f"{path_env}{os.pathsep}{bin_path_str}" + os.environ["PATH"] = new_path_env + os.environ[KCLVM_CLI_BIN_PATH_ENV_VAR] = bin_path_str + self.lib = ctypes.CDLL(os.path.join(path, lib_full_name())) # Assuming the shared library exposes a function `kclvm_service_new` self.lib.kclvm_service_new.argtypes = [ctypes.c_uint64] self.lib.kclvm_service_new.restype = ctypes.c_void_p