我有一个用于预测某些值的代码,该代码在代码中使用xgboost
包。当我在PyCharm中运行它时,它会按预期运行。
问题是当我使用pyinstaller
制作可执行文件时。它将使exe
没有任何错误,但是当我运行它时,将引发以下错误:
`Traceback (most recent call last):
File "test_fraud.py", line 3, in <module>
import xgboost
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File
"C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\xgboost\__init__.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\xgboost\core.py", line 161, in <module>
File "lib\site-packages\xgboost\core.py", line 123, in _load_lib
File "lib\site-packages\xgboost\libpath.py", line 48, in find_lib_path
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\SHUBHA~1\AppData\Local\Temp\_MEI11402\xgboost\xgboost.dll
C:\Users\SHUBHA~1\AppData\Local\Temp\_MEI11402\xgboost
\../../lib/xgboost.dll
C:\Users\SHUBHA~1\AppData\Local\Temp\_MEI11402\xgboost\./lib/xgboost.dll
C:\Users\SHUBHA~1\AppData\Local\Temp\_MEI11402\xgboost\xgboost.dll
C:\Users\SHUBHA~1\AppData\Local\Temp\_MEI11402\xgboost
\../../windows/x64/Release/xgboost.dll
C:\Users\SHUBHA~1\AppData\Local\Temp\_MEI11402\
xgboost\./windows/x64/Release/xgboost.dll
[6564] Failed to execute script test_fraud `
我无法意识到这里出了什么问题。任何想法或建议将不胜感激。
答案 0 :(得分:1)
Pyinstaller似乎找不到xgboost.dll
,VERSION
文件。因此,您需要将它们手动添加到输出包中。我还建议您使用try/except
块来查看发生了什么。
假设这个简单的例子:
import traceback
try:
import xgboost
input("xgboost imported successfully!")
except Exception:
traceback.print_exc()
input("Import Error!")
我建议您使用env来构建脚本,因此,您需要添加位于xgboost
的{{1}}目录和位于{{1}的<path_to_venv>/xgboost
文件}。接下来,使用pyinstaller将它们添加为数据文件。启动您的env并执行以下命令(我的virtualenv名为VERSION
):
<path_to_venv>/Lib/site-packages/xboost
命令:
env