xgboost icon indicating copy to clipboard operation
xgboost copied to clipboard

Pyinstaller and xgboost

Open marcrocasalonso opened this issue 2 years ago • 13 comments

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 "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module File "xgboost/init.py", line 9, in File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module File "xgboost/core.py", line 203, in File "xgboost/core.py", line 157, in _load_lib File "xgboost/libpath.py", line 64, in find_lib_path xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path. List of candidates:

  • /tmp/_MEIHMqWQr/xgboost/lib/libxgboost.so
  • /tmp/_MEIHMqWQr/xgboost/../../lib/libxgboost.so
  • /tmp/_MEIHMqWQr/lib/libxgboost.so XGBoost Python package path: /tmp/_MEIHMqWQr/xgboost sys.prefix: /tmp/_MEIHMqWQr See: https://xgboost.readthedocs.io/en/latest/build.html for installing XGBoost.

I have tray with adding --add-data "path" --add-data"path/VERSION" in the pyinstaller command but did not work.

Any idea about how to solve this problem?

Thanks in advance,

Kind regards, Marc

marcrocasalonso avatar Mar 29 '22 11:03 marcrocasalonso

I don't think XGBoost has been tested with Pyinstaller. If anyone else can jump in and propose a fix, that would be great.

hcho3 avatar Mar 29 '22 17:03 hcho3

I managed to get something similar working by doing;

pip install pipwin pipwin install xgboost

(The latest xgboost version for pipwin is 1.5.1, which may or may not suit your needs)

and then something like;

pyinstaller your.py -F --onefile --add-data "c:\repos\workspaces.env\lib\site-packages\xgboost\xgboost.dll;xgboost" --add-data "c:\repos\workspaces.env\Lib\site-packages\xgboost\VERSION;xgboost"

JSalter2013 avatar Apr 02 '22 02:04 JSalter2013

Dear JSalter2013, I think that your solution could work for windows but not for Linux. Do you know any solution for linux ubuntu?

Thanks in advance,

marcrocasalonso avatar Apr 04 '22 06:04 marcrocasalonso

@marcrocasalonso There are the same error for me. It bothered me for two days.

There is a solution for it. https://github.com/pyinstaller/pyinstaller/pull/4077/commits/a11e82681b697b36b2690ffa8365acd130b8885d

But that commit do not re-target to the https://github.com/pyinstaller/pyinstaller-hooks-contrib repo.

Temporary, add that hook-xgboost.py into PYTHONHOME/lib/site-package/_pyinstaller_hooks_contrib/hooks/stdhooks

then, use your pyinstaller command, pyinstaller --xxxx --collect-all "xgboost"

There solved my problem.

zhnnix avatar Apr 21 '22 01:04 zhnnix

@zhnnix it works

stefanoservino avatar May 26 '22 13:05 stefanoservino

@marcrocasalonso There are the same error for me. It bothered me for two days.

There is a solution for it. pyinstaller/pyinstaller@a11e826

But that commit do not re-target to the https://github.com/pyinstaller/pyinstaller-hooks-contrib repo.

Temporary, add that hook-xgboost.py into PYTHONHOME/lib/site-package/_pyinstaller_hooks_contrib/hooks/stdhooks

then, use your pyinstaller command, pyinstaller --xxxx --collect-all "xgboost"

There solved my problem.

@zhnnix I confirm that your solution resolves this problem! I got two terrible days and now it's working,

Thank you so much

N: for me works by just launch pyinstaller --onefile --noconfirm -F xxxx.py --collect-all "xgboost"

stefanoservino avatar May 26 '22 13:05 stefanoservino

@marcrocasalonso There are the same error for me. It bothered me for two days.

There is a solution for it. pyinstaller/pyinstaller@a11e826

But that commit do not re-target to the https://github.com/pyinstaller/pyinstaller-hooks-contrib repo.

Temporary, add that hook-xgboost.py into PYTHONHOME/lib/site-package/_pyinstaller_hooks_contrib/hooks/stdhooks

then, use your pyinstaller command, pyinstaller --xxxx --collect-all "xgboost"

There solved my problem.

It works! Thank you so much!

7ong30 avatar Jul 05 '22 12:07 7ong30

@zhnnix Does this solution work under linux? I didn't find the hook-xgboost.py file, which directory is this file in? I've been stuck with this problem for days Thank you so much!

Niclouge avatar Jul 19 '22 08:07 Niclouge

@Niclouge Yes, it could work under linux.

This hook-xgboost.py file needs to be added manually. Just like pyinstaller/pyinstaller@a11e826.

This is a temporary solution, but it can be solved immediately.

zhnnix avatar Jul 19 '22 08:07 zhnnix

@Niclouge Yes, it could work under linux.

This hook-xgboost.py file needs to be added manually. Just like pyinstaller/pyinstaller@a11e826.

This is a temporary solution, but it can be solved immediately.

It really works! Super thanks !!!!!

Niclouge avatar Jul 19 '22 09:07 Niclouge

Thank you all for the discussion. Hopefully, the thread can be helpful to others as well.

trivialfis avatar Jan 13 '23 21:01 trivialfis

Hi,

I have followed the above solutions, and the xgboost package can be included by pyinstaller. However, I have found that some python files of xgboost have been added in the dist files. Can I convert these python files to pyd files somehow ?

KarenMars avatar Sep 08 '23 06:09 KarenMars