libpath.py 1.17 KB
Newer Older
wxchan's avatar
wxchan committed
1
# coding: utf-8
2
"""Find the path to LightGBM dynamic library files."""
3

4
from pathlib import Path
5
from platform import system
Deddy Jobson's avatar
Deddy Jobson committed
6
from typing import List
7

8
__all__: List[str] = []
9

wxchan's avatar
wxchan committed
10

Deddy Jobson's avatar
Deddy Jobson committed
11
def find_lib_path() -> List[str]:
wxchan's avatar
wxchan committed
12
    """Find the path to LightGBM library files.
13

wxchan's avatar
wxchan committed
14
15
    Returns
    -------
16
    lib_path: list of str
17
       List of all found library paths to LightGBM.
wxchan's avatar
wxchan committed
18
    """
19
    curr_path = Path(__file__).absolute()
20
21
22
23
24
25
26
27
28
    dll_path = [
        curr_path.parents[1],
        curr_path.parents[0] / "bin",
        curr_path.parents[0] / "lib",
    ]
    if system() in ("Windows", "Microsoft"):
        dll_path.append(curr_path.parents[1] / "Release")
        dll_path.append(curr_path.parents[1] / "windows" / "x64" / "DLL")
        dll_path = [p / "lib_lightgbm.dll" for p in dll_path]
29
30
    elif system() == "Darwin":
        dll_path = [p / "lib_lightgbm.dylib" for p in dll_path]
wxchan's avatar
wxchan committed
31
    else:
32
        dll_path = [p / "lib_lightgbm.so" for p in dll_path]
33
    lib_path = [str(p) for p in dll_path if p.is_file()]
wxchan's avatar
wxchan committed
34
    if not lib_path:
35
36
        dll_path_joined = "\n".join(map(str, dll_path))
        raise Exception(f"Cannot find lightgbm library file in following paths:\n{dll_path_joined}")
wxchan's avatar
wxchan committed
37
    return lib_path