diff --git a/fastdeploy/__init__.py b/fastdeploy/__init__.py index 17858f7e9..69384cea4 100644 --- a/fastdeploy/__init__.py +++ b/fastdeploy/__init__.py @@ -13,13 +13,31 @@ # limitations under the License. from __future__ import absolute_import import logging +import os +import sys + +def add_dll_search_dir(dir_path): + os.environ["path"] = dir_path + ";" + os.environ["path"] + sys.path.insert(0, dir_path) + if sys.version_info[:2] >= (3, 8): + os.add_dll_directory(dir_path) + +if os.name == "nt": + current_path = os.path.abspath(__file__) + dirname = os.path.dirname(current_path) + third_libs_dir = os.path.join(dirname, "libs") + add_dll_search_dir(third_libs_dir) + for root, dirs, filenames in os.walk(third_libs_dir): + for d in dirs: + if d == "lib": + add_dll_search_dir(os.path.join(dirname, root, d)) + from .fastdeploy_main import Frontend, Backend, FDDataType, TensorInfo, Device from .fastdeploy_runtime import * from . import fastdeploy_main as C from . import vision from .download import download, download_and_decompress - def TensorInfoStr(tensor_info): message = "TensorInfo(name : '{}', dtype : '{}', shape : '{}')".format( tensor_info.name, tensor_info.dtype, tensor_info.shape) @@ -28,7 +46,7 @@ def TensorInfoStr(tensor_info): class RuntimeOption: def __init__(self): - self._option = C.RuntimeOption() + self._option = C.RuntimeOption() def set_model_path(self, model_path, params_path="", model_format="paddle"): return self._option.set_model_path(model_path, params_path, model_format) @@ -103,5 +121,6 @@ def RuntimeOptionStr(runtime_option): message.strip("\n") message += ")" return message + C.TensorInfo.__repr__ = TensorInfoStr -C.RuntimeOption.__repr__ = RuntimeOptionStr +C.RuntimeOption.__repr__ = RuntimeOptionStr \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f2293605c..2c8b74ebd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ requests +tqdm \ No newline at end of file diff --git a/setup.py b/setup.py index fcaaa9f37..12cc65d98 100644 --- a/setup.py +++ b/setup.py @@ -362,6 +362,16 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel": "fastdeploy/libs/third_libs", symlinks=True) + if platform.system().lower() == "windows": + release_dir = os.path.join(".setuptools-cmake-build", "Release") + for f in os.listdir(release_dir): + filename = os.path.join(release_dir, f) + if not os.path.isfile(filename): + continue + if filename.endswith(".pyd"): + continue + shutil.copy(filename, "fastdeploy/libs") + if platform.system().lower() == "linux": rpaths = ["$ORIGIN:$ORIGIN/libs"] for root, dirs, files in os.walk(