Skip to content

Commit 946ab53

Browse files
authored
Fix libpath logic for Windows (dmlc#9687)
1 parent afd03a6 commit 946ab53

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

python-package/packager/nativelib.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,28 @@ def locate_or_build_libxgboost(
132132

133133
if build_config.use_system_libxgboost:
134134
# Find libxgboost from system prefix
135-
sys_base_prefix = pathlib.Path(sys.base_prefix).absolute().resolve()
136-
libxgboost_sys = sys_base_prefix / "lib" / _lib_name()
137-
if not libxgboost_sys.exists():
138-
raise RuntimeError(
139-
f"use_system_libxgboost was specified but {_lib_name()} is "
140-
f"not found in {libxgboost_sys.parent}"
141-
)
142-
143-
logger.info("Using system XGBoost: %s", str(libxgboost_sys))
144-
return libxgboost_sys
135+
sys_prefix = pathlib.Path(sys.prefix)
136+
sys_prefix_candidates = [
137+
sys_prefix / "lib",
138+
# Paths possibly used on Windows
139+
sys_prefix / "bin",
140+
sys_prefix / "Library",
141+
sys_prefix / "Library" / "bin",
142+
sys_prefix / "Library" / "lib",
143+
]
144+
sys_prefix_candidates = [
145+
p.expanduser().resolve() for p in sys_prefix_candidates
146+
]
147+
for candidate_dir in sys_prefix_candidates:
148+
libtreelite_sys = candidate_dir / _lib_name()
149+
if libtreelite_sys.exists():
150+
logger.info("Using system XGBoost: %s", str(libtreelite_sys))
151+
return libtreelite_sys
152+
raise RuntimeError(
153+
f"use_system_libxgboost was specified but {_lib_name()} is "
154+
f"not found. Paths searched (in order): \n"
155+
+ "\n".join([f"* {str(p)}" for p in sys_prefix_candidates])
156+
)
145157

146158
libxgboost = locate_local_libxgboost(toplevel_dir, logger=logger)
147159
if libxgboost is not None:

python-package/xgboost/libpath.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ def find_lib_path() -> List[str]:
3131
]
3232

3333
if sys.platform == "win32":
34-
if platform.architecture()[0] == "64bit":
35-
dll_path.append(os.path.join(curr_path, "../../windows/x64/Release/"))
36-
# hack for pip installation when copy all parent source
37-
# directory here
38-
dll_path.append(os.path.join(curr_path, "./windows/x64/Release/"))
39-
else:
40-
dll_path.append(os.path.join(curr_path, "../../windows/Release/"))
41-
# hack for pip installation when copy all parent source
42-
# directory here
43-
dll_path.append(os.path.join(curr_path, "./windows/Release/"))
34+
# On Windows, Conda may install libs in different paths
35+
dll_path.extend(
36+
[
37+
os.path.join(sys.prefix, "bin"),
38+
os.path.join(sys.prefix, "Library"),
39+
os.path.join(sys.prefix, "Library", "bin"),
40+
os.path.join(sys.prefix, "Library", "lib"),
41+
]
42+
)
4443
dll_path = [os.path.join(p, "xgboost.dll") for p in dll_path]
4544
elif sys.platform.startswith(("linux", "freebsd", "emscripten")):
4645
dll_path = [os.path.join(p, "libxgboost.so") for p in dll_path]

0 commit comments

Comments
 (0)