python - 导入 xgboost 模块时出现问题(错误消息:['[WinError 193] %1 is not a valid Win32 application'])
问题描述
我已经使用 xgboost-1.1.0-cp37-cp37m-win32.whl 安装了 xgboost 错误说要安装两个 vcomp140.dll 或 libgomp-1.dll 中的任何一个我都尝试过,但没有显示结果我没有使用 conda 我我正在使用 jupyter 笔记本。
import xgboost
XGBoostError Traceback (most recent call last)
<ipython-input-1-e444c8490328> in <module>
----> 1 from xgboost import XGBRegressor
2 from sklearn.model_selection import train_test_split
3 from sklearn.metrics import accuracy_score
c:\users\aarja\appdata\local\programs\python\python37-32\lib\site-packages\xgboost\__init__.py in <module>
9 import warnings
10
---> 11 from .core import DMatrix, DeviceQuantileDMatrix, Booster
12 from .training import train, cv
13 from . import rabit # noqa
c:\users\aarja\appdata\local\programs\python\python37-32\lib\site-packages\xgboost\core.py in <module>
173
174 # load the XGBoost library globally
--> 175 _LIB = _load_lib()
176
177
c:\users\aarja\appdata\local\programs\python\python37-32\lib\site-packages\xgboost\core.py in _load_lib()
164 '`brew install libomp` to install OpenMP runtime.\n' +
165 ' * You are running 32-bit Python on a 64-bit OS\n' +
--> 166 'Error message(s): {}\n'.format(os_error_list))
167 lib.XGBGetLastError.restype = ctypes.c_char_p
168 lib.callback = _get_log_callback_func()
XGBoostError: XGBoost Library (xgboost.dll) could not be loaded.
Likely causes:
* OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libomp.dylib for Mac OSX, libgomp.so for Linux and other UNIX-like OSes). Mac OSX users: Run `brew install libomp` to install OpenMP runtime.
* You are running 32-bit Python on a 64-bit OS
Error message(s): ['[WinError 193] %1 is not a valid Win32 application']
解决方案
问题很可能在于缺少 Visual Studio C++ Redistributable binaries。
您可以从官方链接安装它们。它们是在 Windows 上编译的许多 C++ 库的依赖项,这些库公开了 Python API(或实际上连接到 C++ 库的 Python 模块)。
在您的情况下,假设安装顺利,OpenMP 已安装,但缺少它的依赖项。如果您在安装 VC Redist 软件包后遇到类似问题,那么您应该检查 OpenMP DLL 的安装。pip install xgboost
或者在 64b Windows 上安装预编译版本。
推荐阅读
- c# - 如何在 C# 中聚合 order by?
- java - Log4j2 中的 JMS Appender 出错,转到 Wildfly 14
- microsoft-dynamics - Econnect 警告:使用了分布式事务
- python - Python 静态方法有什么用处(命名空间除外)?
- vba - 这些对话标题是什么类型的?
- php - 如何在 Laravel 中选择后对结果进行分组
- javascript - Webscraper 函数返回未定义
- css - 错误字段未以 django 形式正确显示
- javascript - 如果我检查值的长度(文本字段),javascript 输出不显示
- javascript - 是否可以在 Javascript 中使用 HTML Helpers?