我正在尝试使用pyinstaller打包我编写的使用xgboost的程序。 .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:\Users\MHAMIL~1\AppData\Local\Temp\_MEI115602\xgboost\xgboost.dll
C:\Users\MHAMIL~1\AppData\Local\Temp\_MEI115602\xgboost\../../lib/xgboost.dll
C:\Users\MHAMIL~1\AppData\Local\Temp\_MEI115602\xgboost\./lib/xgboost.dll
C:\Users\MHAMIL~1\AppData\Local\Temp\_MEI115602\xgboost\xgboost.dll
C:\Users\MHAMIL~1\AppData\Local\Temp\_MEI115602\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\MHAMIL~1\AppData\Local\Temp\_MEI115602\xgboost\./windows/x64/Release/xgboost.dll
[26104] Failed to execute script __main__
从我完成的搜索看来,这与二进制文件不可用于exe的原因有关。我已经在.spec文件中为sklearn和xgboost添加了它们,因为我最初对sklearn有类似的问题。在.spec文件中添加二进制文件可以解决sklearn的问题,但不能解决xgboost的问题。以下是我将它们添加到.spec文件中的方法:
datas, binaries, hiddenimports = collect_all("xgboost")
a = Analysis(['__main__.py'],
pathex=['C:\\Users\\mhamilton\\Documents\\Projects\\forecast\\production'],
binaries=[('C:\\Users\\mhamilton\\AppData\\Local\\Programs\\Python\\Python38\\Lib\\site-packages\\sklearn\\.libs\\vcomp140.dll','.'),
('C:\\Users\\mhamilton\\AppData\\Local\\Programs\\Python\\Python38\\xgboost\\xgboost.dll','.')],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
如果有人解决了这个问题或类似的问题,我将不胜感激您的专业知识!