From f7a2be93150c5a86ff4367c9f4fae705f51cf90a Mon Sep 17 00:00:00 2001 From: DefTruth <31974251+DefTruth@users.noreply.github.com> Date: Thu, 18 Aug 2022 10:24:03 +0800 Subject: [PATCH] [win][conda] fix conda import error on windows (#126) --- fastdeploy/c_lib_wrap.py.in | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fastdeploy/c_lib_wrap.py.in b/fastdeploy/c_lib_wrap.py.in index 2c38d101d..6af53fc7c 100644 --- a/fastdeploy/c_lib_wrap.py.in +++ b/fastdeploy/c_lib_wrap.py.in @@ -79,6 +79,22 @@ def add_cuda_shared_lib_dir_windows(): print(f"[FastDeploy][CUDA]: Found valid cuda directroy and added it: -> {cuda_shared_lib_dir}") +def try_pre_load_fastdeploy_dll(dll_name=None): + # Try pre-load fastdeploy dll in windows to + # make sure the added custom dll directory + # has been activated. Reference: + # [1] https://github.com/conda/conda/issues/10897 + # [2] https://github.com/dhermes/bezier/issues/237 + from ctypes import cdll + if dll_name is None: + dll_name = "fastdeploy.dll" + try: + dll = cdll.LoadLibrary(dll_name) + del dll + except Exception as e: + raise RuntimeError(f"Can not pre load dll: {dso_name}. {e}") + + if os.name == "nt": add_cuda_shared_lib_dir_windows() current_path = os.path.abspath(__file__) @@ -89,6 +105,7 @@ if os.name == "nt": for d in dirs: if d == "lib" or d == "bin": add_dll_search_dir(os.path.join(dirname, root, d)) + try_pre_load_fastdeploy_dll() try: