python - 无法在 Python 中导入 xgboost
问题描述
我已经使用 Python 2.7.16 的 pip 成功安装了 xgboost(我在 macOS High Sierra 上使用 Homebrew 安装了这个 Python 版本)。我的问题是我无法在 Python 中导入 xgboost,根据以下错误消息:
mac-128644:~ user$ python
Python 2.7.16 (default, Apr 12 2019, 15:32:52)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/xgboost/__init__.py", line 11, in <module>
from .core import DMatrix, Booster
File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 163, in <module>
_LIB = _load_lib()
File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 154, in _load_lib
'Error message(s): {}\n'.format(os_error_list))
xgboost.core.XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded.
Likely causes:
* OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libgomp.so for UNIX-like OSes)
* You are running 32-bit Python on a 64-bit OS
Error message(s): ['dlopen(/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/8/libgomp.1.dylib\n Referenced from: /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib\n Reason: no suitable image found. Did find:\n\t/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib/libgomp.1.dylib: stat() failed with errno=20']
我已经确定我的 Python 版本和操作系统都是 64 位的,所以这个问题绝对不是第二个“可能的原因”。我也很确定我已经安装了 OpenMP:查找说明,就我而言,我会这样做brew install llvm
并且安装成功。我也不确定为什么它似乎找不到/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib
,因为我可以cd
进入该目录并看到libxgboost.dylib
很好。看起来稍后在它确实找到它的消息中,但仍然抛出错误?这里到底发生了什么,我能做些什么来解决这个错误?
解决方案
先安装 xgboost:
pip install xgboost
然后使用:
brew install libomp
最后:
import xgboost as
推荐阅读
- javascript - 在扩展数组上调用 splice 会导致错误,我不知道为什么
- firebase - Firebase + React Native + 使用 Apple 登录
- tensorflow - 训练和验证模式 tensorflow 的 SAME 数据丢失不一致
- python - 如何根据列值拆分数据框中的行?
- reactjs - 插件属性未添加到 React 中的 FilePond 对象
- android - Ionic cordova plugin ble central,如何在编写特性之前等待Android 9/10配对请求解决?
- javascript - 我需要制作一个 JavaScript 函数,当用户单击“搜索”按钮时将调用该函数
- rest - 在 REST API 中执行 SalesOrderAddInvoice 操作
- javascript - 调用这个和函数参数
- android - Android改造只显示部分结果