xgboost 无法在 Mac 中加载

Dan*_*ish 1 python-3.x xgboost

我正在尝试运行下面的代码。这是https://github.com/krishnaik06的 GitHub 代码。

jupyter笔记本的链接如下。

https://github.com/krishnaik06/Credit_Card-Risk-assessment/blob/master/Credit%20Card%20Risk%20Assessment.ipynb

我无法加载 xgboost 的地方

尝试在单元格下方运行,它显示一些错误。

## Hyperparameter optimization using RandomizedSearchCV
from sklearn.model_selection import RandomizedSearchCV, GridSearchCV
import xgboost
Run Code Online (Sandbox Code Playgroud)

错误:

---------------------------------------------------------------------------
XGBoostError                              Traceback (most recent call last)
<ipython-input-11-60e28ccb95f6> in <module>
      1 ## Hyperparameter optimization using RandomizedSearchCV
      2 from sklearn.model_selection import RandomizedSearchCV, GridSearchCV
----> 3 import xgboost

~/opt/anaconda3/lib/python3.8/site-packages/xgboost/__init__.py in <module>
      7 import os
      8 
----> 9 from .core import DMatrix, DeviceQuantileDMatrix, Booster
     10 from .training import train, cv
     11 from . import rabit  # noqa

~/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in <module>
    171 
    172 # load the XGBoost library globally
--> 173 _LIB = _load_lib()
    174 
    175 

~/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in _load_lib()
    154     if not lib_success:
    155         libname = os.path.basename(lib_paths[0])
--> 156         raise XGBoostError(
    157             'XGBoost Library ({}) could not be loaded.\n'.format(libname) +
    158             '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(/Users/danishali/opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib\n  Referenced from: /Users/danishali/opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib\n  Reason: image not found']
Run Code Online (Sandbox Code Playgroud)

我尝试过的:

  1. 卸载的 anaconda
  2. 安装了 anaconda 和 64 位 python。

还是同样的错误

小智 6

首先,我通过pip安装了xgboost,我得到了同样的错误。然后,我通过代码:卸载了它pip uninstall xgboost,并通过代码:再次通过anaconda安装了它conda install py-xgboost。现在我可以import xgboost 没有错误了。