Skip to content

Commit

Permalink
handle $PATH not being set in python library (#3845)
Browse files Browse the repository at this point in the history
Fixes #3844
  • Loading branch information
JelleZijlstra authored and hcho3 committed Nov 6, 2018
1 parent 1bf4083 commit d9642cf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,23 @@ def _load_lib():
lib_paths = find_lib_path()
if len(lib_paths) == 0:
return None
pathBackup = os.environ['PATH']
try:
pathBackup = os.environ['PATH'].split(os.pathsep)
except KeyError:
pathBackup = []
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)
os.environ['PATH'] = os.pathsep.join(pathBackup + [os.path.dirname(lib_path)])
lib = ctypes.cdll.LoadLibrary(lib_path)
lib_success = True
except OSError as e:
os_error_list.append(str(e))
continue
finally:
os.environ['PATH'] = os.pathsep.join(pathBackup)
if not lib_success:
libname = os.path.basename(lib_paths[0])
raise XGBoostError(
Expand Down

0 comments on commit d9642cf

Please sign in to comment.