Skip to content

Commit

Permalink
Better error message for failed library loading (dmlc#3690)
Browse files Browse the repository at this point in the history
* Better error message for failed lib loading

* Address review comment + fix lint
  • Loading branch information
hcho3 authored Sep 13, 2018
1 parent 3209b42 commit bd41bd6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,27 @@ def _load_lib():
if len(lib_paths) == 0:
return None
pathBackup = os.environ['PATH']
lib_success = False
os_error_list = []
for lib_path in lib_paths:
try:
# needed when the lib is linked with non-system-available dependencies
os.environ['PATH'] = pathBackup + os.pathsep + os.path.dirname(lib_path)
lib = ctypes.cdll.LoadLibrary(lib_path)
except OSError:
lib_success = True
except OSError as e:
os_error_list.append(str(e))
continue
if not lib_success:
libname = os.path.basename(lib_paths[0])
raise XGBoostError(
'XGBoost Library ({}) could not be loaded.\n'.format(libname) +
'Likely causes:\n' +
' * OpenMP runtime is not installed ' +
'(vcomp140.dll or libgomp-1.dll for Windows, ' +
'libgomp.so for UNIX-like OSes)\n' +
' * You are running 32-bit Python on a 64-bit OS\n' +
'Error message(s): {}\n'.format(os_error_list))
lib.XGBGetLastError.restype = ctypes.c_char_p
lib.callback = _get_log_callback_func()
if lib.XGBRegisterLogCallback(lib.callback) != 0:
Expand Down

0 comments on commit bd41bd6

Please sign in to comment.