Skip to content

Commit 8e7b540

Browse files
authored
Fix python usage on Windows (#60)
* Polish compilation on Windows * Fix python usage on Windows
1 parent 3a2b86f commit 8e7b540

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

fastdeploy/__init__.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,31 @@
1313
# limitations under the License.
1414
from __future__ import absolute_import
1515
import logging
16+
import os
17+
import sys
18+
19+
def add_dll_search_dir(dir_path):
20+
os.environ["path"] = dir_path + ";" + os.environ["path"]
21+
sys.path.insert(0, dir_path)
22+
if sys.version_info[:2] >= (3, 8):
23+
os.add_dll_directory(dir_path)
24+
25+
if os.name == "nt":
26+
current_path = os.path.abspath(__file__)
27+
dirname = os.path.dirname(current_path)
28+
third_libs_dir = os.path.join(dirname, "libs")
29+
add_dll_search_dir(third_libs_dir)
30+
for root, dirs, filenames in os.walk(third_libs_dir):
31+
for d in dirs:
32+
if d == "lib":
33+
add_dll_search_dir(os.path.join(dirname, root, d))
34+
1635
from .fastdeploy_main import Frontend, Backend, FDDataType, TensorInfo, Device
1736
from .fastdeploy_runtime import *
1837
from . import fastdeploy_main as C
1938
from . import vision
2039
from .download import download, download_and_decompress
2140

22-
2341
def TensorInfoStr(tensor_info):
2442
message = "TensorInfo(name : '{}', dtype : '{}', shape : '{}')".format(
2543
tensor_info.name, tensor_info.dtype, tensor_info.shape)
@@ -28,7 +46,7 @@ def TensorInfoStr(tensor_info):
2846

2947
class RuntimeOption:
3048
def __init__(self):
31-
self._option = C.RuntimeOption()
49+
self._option = C.RuntimeOption()
3250

3351
def set_model_path(self, model_path, params_path="", model_format="paddle"):
3452
return self._option.set_model_path(model_path, params_path, model_format)
@@ -103,5 +121,6 @@ def RuntimeOptionStr(runtime_option):
103121
message.strip("\n")
104122
message += ")"
105123
return message
124+
106125
C.TensorInfo.__repr__ = TensorInfoStr
107-
C.RuntimeOption.__repr__ = RuntimeOptionStr
126+
C.RuntimeOption.__repr__ = RuntimeOptionStr

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests
2+
tqdm

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ def run(self):
362362
"fastdeploy/libs/third_libs",
363363
symlinks=True)
364364

365+
if platform.system().lower() == "windows":
366+
release_dir = os.path.join(".setuptools-cmake-build", "Release")
367+
for f in os.listdir(release_dir):
368+
filename = os.path.join(release_dir, f)
369+
if not os.path.isfile(filename):
370+
continue
371+
if filename.endswith(".pyd"):
372+
continue
373+
shutil.copy(filename, "fastdeploy/libs")
374+
365375
if platform.system().lower() == "linux":
366376
rpaths = ["$ORIGIN:$ORIGIN/libs"]
367377
for root, dirs, files in os.walk(

0 commit comments

Comments
 (0)