문제 상황

xgboost를 import한 .py 파일을 pyinstaller로 .exe 로 패키징 할 때 다음과 같은 에러를 출력

xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\...\AppData\Local\Temp\_MEI103562\xgboost\xgboost.dll
C:\...\AppData\Local\Temp\_MEI103562\xgboost\../../lib/xgboost.dll
C:\...\AppData\Local\Temp\_MEI103562\xgboost\./lib/xgboost.dll
C:\...\AppData\Local\Temp\_MEI103562\xgboost\xgboost.dll
C:\...\AppData\Local\Temp\_MEI103562\xgboost\../../windows/x64/Release/xgboost.dll
C:\...\AppData\Local\Temp\_MEI103562\xgboost\./windows/x64/Release/xgboost.dllCopy Icon

해결 방법

다음 글을 참고

https://github.com/dmlc/xgboost/issues/7761#issuecomment-1104619556

 

Pyinstaller and xgboost · Issue #7761 · dmlc/xgboost

Dear coders, I am trying to launch pyinstaller for my app but it appear the commun error with xgboost and pyinstaller. I am using xgboost version 1.5.2. The error is : import xgboost as xgb File ""...

github.com

 

1. 파일 추가

[PYTHON PATH]\Lib/site-package/_pyinstaller_hooks_contrib/stdhooks 폴더에 hook-xgboost.py 파일을 생성

""" hook-xgboost.py """
from PyInstaller.utils.hooks import collect_all
datas, binaries, hiddenimports = collect_all("xgboost")Copy Icon

2. 패키징

pyinstaller --collect-all "xgboost" test.pyCopy Icon

--add-data "[file_path]; [dir_path]"

--hidden-import "[library]"

욱근욱