Skip to content

Commit a393d44

Browse files
KOLANICHhcho3
authored andcommitted
Improved library loading a bit (dmlc#3481)
* Improved library loading a bit * Fixed indentation. * Fixes according to the discussion * Moved the comment to a separate line. * specified exception type
1 parent 8e90b60 commit a393d44

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

python-package/xgboost/core.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,17 @@ def _get_log_callback_func():
114114

115115
def _load_lib():
116116
"""Load xgboost Library."""
117-
lib_path = find_lib_path()
118-
if len(lib_path) == 0:
117+
lib_paths = find_lib_path()
118+
if len(lib_paths) == 0:
119119
return None
120-
lib = ctypes.cdll.LoadLibrary(lib_path[0])
120+
pathBackup = os.environ['PATH']
121+
for lib_path in lib_paths:
122+
try:
123+
# needed when the lib is linked with non-system-available dependencies
124+
os.environ['PATH'] = pathBackup + os.pathsep + os.path.dirname(lib_path)
125+
lib = ctypes.cdll.LoadLibrary(lib_path)
126+
except OSError:
127+
continue
121128
lib.XGBGetLastError.restype = ctypes.c_char_p
122129
lib.callback = _get_log_callback_func()
123130
if lib.XGBRegisterLogCallback(lib.callback) != 0:

0 commit comments

Comments
 (0)