可执行文件中的问题 运行 Xgboost
Problem Running Xgboost in Executable File
我在使用 PyInstaller
创建的可执行文件中使用保存的 Xgboost
模型。我设置了一个虚拟环境并下载了 Xgboost
并确保它 运行 但是在我创建了 exe 和 运行 exe 之后我得到了关于 xgboost.core
:
的错误
ModuleNotFoundError: No module nemed 'xgboost.core'
实际上我看不到 xgboost 有任何导入问题,首先,请确保您在环境中使用最新版本 pip install -U xgboost
然后尝试添加 xgboost.core
作为 hidden-import
并将 xgboost 的 DLL 添加为 data-files
.
假设你的 virtualenv 被命名为 env
,使用下面的命令来生成你的可执行文件:
├───myscript.py
├───env
代码:
import traceback
try:
from xgboost import core
input("xgboost.core imported successfully!")
except Exception:
traceback.print_exc()
input("Import Error!")
命令:
(env) > pyinstaller myscript.py -F --hidden-import=xgboost.core --add-data "./env/xgboost/*;xgboost/"
--add-data "./env/Lib/site-packages/xgboost/VERSION;xgboost/"
@Masoud Rahimi 的回答对我不起作用。 运行 pyinstaller 使用 --collect-all
选项做了什么:
pyinstaller -D <app_name>.py --noconfirm --collect-all "xgboost"
见this issue and the arguments in the pyinstaller manual
我在使用 PyInstaller
创建的可执行文件中使用保存的 Xgboost
模型。我设置了一个虚拟环境并下载了 Xgboost
并确保它 运行 但是在我创建了 exe 和 运行 exe 之后我得到了关于 xgboost.core
:
ModuleNotFoundError: No module nemed 'xgboost.core'
实际上我看不到 xgboost 有任何导入问题,首先,请确保您在环境中使用最新版本 pip install -U xgboost
然后尝试添加 xgboost.core
作为 hidden-import
并将 xgboost 的 DLL 添加为 data-files
.
假设你的 virtualenv 被命名为 env
,使用下面的命令来生成你的可执行文件:
├───myscript.py
├───env
代码:
import traceback
try:
from xgboost import core
input("xgboost.core imported successfully!")
except Exception:
traceback.print_exc()
input("Import Error!")
命令:
(env) > pyinstaller myscript.py -F --hidden-import=xgboost.core --add-data "./env/xgboost/*;xgboost/"
--add-data "./env/Lib/site-packages/xgboost/VERSION;xgboost/"
@Masoud Rahimi 的回答对我不起作用。 运行 pyinstaller 使用 --collect-all
选项做了什么:
pyinstaller -D <app_name>.py --noconfirm --collect-all "xgboost"
见this issue and the arguments in the pyinstaller manual