在Jupyter Notebook上导入Xgboost时遇到此简单问题

时间:2020-05-23 12:14:56

标签: python jupyter-notebook jupyter xgboost

在我导入Xgboost之前,在Jupyter笔记本电脑上一切正常。导入后,立即出现以下问题。我有Python 3.8,并已通过终端pip3方法安装了它,下一步该怎么办?

---------------------------------------------------------------------------
XGBoostError                              Traceback (most recent call last)
<ipython-input-17-a81e4513ce38> in <module>
      1 # Let's Learn about the stock market using XGBOOST
      2 
----> 3 import xgboost as xgb

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/xgboost/core.py in <module>
    173 
    174 # load the XGBoost library globally
--> 175 _LIB = _load_lib()
    176 
    177 

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/xgboost/core.py in _load_lib()
    156     if not lib_success:
    157         libname = os.path.basename(lib_paths[0])
--> 158         raise XGBoostError(
    159             'XGBoost Library ({}) could not be loaded.\n'.format(libname) +
    160             'Likely causes:\n' +

XGBoostError: XGBoost Library (libxgboost.dylib) 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): ['dlopen(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib\n  Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib\n  Reason: image not found']

6 个答案:

答案 0 :(得分:13)

我通过安装Mac OSX的libomp.dylib解决了该问题。答案一直在那里。

答案 1 :(得分:2)

对于Mac OSX,只需运行“ brew install libomp” enter image description here

答案 2 :(得分:2)

您必须先在您的 MAC 上安装 brew:https://brew.sh/(Brew 可能需要一些时间来安装) 然后在终端中运行以下命令:brew install libomp

答案 3 :(得分:1)

如果你使用anaconda,你可以使用:

conda install py-xgboost

答案 4 :(得分:0)

如果你有 Python 3.7 或更高版本,你可以按照下面的方法解决:

!brew install libomp

答案 5 :(得分:0)

如果您使用的是 anaconda,下面的命令对我有用

conda install -c conda-forge xgboost