无法在Python中导入xgboost

时间:2019-05-21 14:29:53

标签: python macos python-import importerror xgboost

我已使用pip for Python 2.7.16成功安装了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版本和OS都是64位的,因此问题绝对不是第二个“可能的原因”。我也很确定我已经安装了OpenMP:查找说明,就我而言,我会brew install llvm进行安装,并且安装成功。我也不确定为什么似乎找不到/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib,因为我可以cd进入该目录并看到libxgboost.dylib很好。看起来稍后在它 did 找到它的消息中,但仍然抛出错误?到底发生了什么,我该怎么办才能解决此错误?

1 个答案:

答案 0 :(得分:-1)

先安装xgboost:

pip install xgboost

然后使用:

brew install libomp

最后:

import xgboost as