Skip to content

Commit

Permalink
Fix libpath logic for Windows (#9687)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 authored Oct 19, 2023
1 parent afd03a6 commit 946ab53
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
32 changes: 22 additions & 10 deletions python-package/packager/nativelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,28 @@ def locate_or_build_libxgboost(

if build_config.use_system_libxgboost:
# Find libxgboost from system prefix
sys_base_prefix = pathlib.Path(sys.base_prefix).absolute().resolve()
libxgboost_sys = sys_base_prefix / "lib" / _lib_name()
if not libxgboost_sys.exists():
raise RuntimeError(
f"use_system_libxgboost was specified but {_lib_name()} is "
f"not found in {libxgboost_sys.parent}"
)

logger.info("Using system XGBoost: %s", str(libxgboost_sys))
return libxgboost_sys
sys_prefix = pathlib.Path(sys.prefix)
sys_prefix_candidates = [
sys_prefix / "lib",
# Paths possibly used on Windows
sys_prefix / "bin",
sys_prefix / "Library",
sys_prefix / "Library" / "bin",
sys_prefix / "Library" / "lib",
]
sys_prefix_candidates = [
p.expanduser().resolve() for p in sys_prefix_candidates
]
for candidate_dir in sys_prefix_candidates:
libtreelite_sys = candidate_dir / _lib_name()
if libtreelite_sys.exists():
logger.info("Using system XGBoost: %s", str(libtreelite_sys))
return libtreelite_sys
raise RuntimeError(
f"use_system_libxgboost was specified but {_lib_name()} is "
f"not found. Paths searched (in order): \n"
+ "\n".join([f"* {str(p)}" for p in sys_prefix_candidates])
)

libxgboost = locate_local_libxgboost(toplevel_dir, logger=logger)
if libxgboost is not None:
Expand Down
19 changes: 9 additions & 10 deletions python-package/xgboost/libpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ def find_lib_path() -> List[str]:
]

if sys.platform == "win32":
if platform.architecture()[0] == "64bit":
dll_path.append(os.path.join(curr_path, "../../windows/x64/Release/"))
# hack for pip installation when copy all parent source
# directory here
dll_path.append(os.path.join(curr_path, "./windows/x64/Release/"))
else:
dll_path.append(os.path.join(curr_path, "../../windows/Release/"))
# hack for pip installation when copy all parent source
# directory here
dll_path.append(os.path.join(curr_path, "./windows/Release/"))
# On Windows, Conda may install libs in different paths
dll_path.extend(
[
os.path.join(sys.prefix, "bin"),
os.path.join(sys.prefix, "Library"),
os.path.join(sys.prefix, "Library", "bin"),
os.path.join(sys.prefix, "Library", "lib"),
]
)
dll_path = [os.path.join(p, "xgboost.dll") for p in dll_path]
elif sys.platform.startswith(("linux", "freebsd", "emscripten")):
dll_path = [os.path.join(p, "libxgboost.so") for p in dll_path]
Expand Down

0 comments on commit 946ab53

Please sign in to comment.