简体   繁体   English

在 Jupyter 笔记本上导入 Xgboost 时遇到这个简单的问题

[英]Getting this simple problem while importing Xgboost on Jupyter notebook

Everything was running fine in Jupyter notebook until I imported Xgboost.在我导入 Xgboost 之前,Jupyter 笔记本中的一切都运行良好。 As soon as I import it I get the problem below.一旦我导入它,我就会遇到以下问题。 I have Python 3.8 and have installed it via terminal pip3 method, what should I do next?我有 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']

I solved it by installing libomp.dylib for Mac OSX.我通过为 Mac OSX 安装 libomp.dylib 解决了这个问题。 The answer was there all along.答案一直都在。

You can do it by running the following command:您可以通过运行以下命令来执行此操作:

brew install libomp

for Mac OSX, just run 'brew install libomp'对于 Mac OSX,只需运行 'brew install libomp' 在此处输入图像描述

You must install brew on your MAC first: https://brew.sh/ (Brew might take a moment to install) Then run the following in your terminal: brew install libomp您必须先在您的 MAC 上安装 brew: https://brew.sh/ (Brew 可能需要一些时间来安装)然后在您的终端中运行以下命令: brew install libomp

If you use anaconda, you can use:如果您使用 anaconda,您可以使用:

conda install py-xgboost

You can solve it as below if you have Python 3.7 or higher:如果您有 Python 3.7 或更高版本,您可以如下解决:

!brew install libomp

Below command worked for me if you are using anaconda如果您使用的是 anaconda,以下命令对我有用

conda install -c conda-forge xgboost

If brew install libomp doesn't work, libomp might be installed to a different place.如果brew install libomp不起作用,则可能是libomp安装到了不同的位置。

xgboost needs libomp.dylib under usr/local/opt/libomp/lib/libomp.dylib , but brew may install it under /opt/brew/Cellar/libomp/11.0.1/lib/libomp.dylib . xgboost 需要libomp.dylibusr/local/opt/libomp/lib/libomp.dylib ,但brew可能会在/opt/brew/Cellar/libomp/11.0.1/lib/libomp.dylib下安装它。 You can copy yours to the xgboost required path.您可以将您的复制到 xgboost 所需的路径。

The cause is that xgboost is looking for the dynamic library at the following locations, which is not where it might be installed to.原因是 xgboost 正在以下位置寻找动态库,这不是它可能安装到的位置。

Reason: tried: '/libomp.dylib' (no such file), '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/libomp.dylib' (no such file), '/Users/michaeltu/third-party/lib/libomp.dylib' (no such file)"]

First, brew install libomp if you haven't done so.首先,如果您还没有这样做, brew install libomp

After that, check where brew installed the library.之后,检查 brew 安装库的位置。

$ brew info libomp
libomp: stable 12.0.0 (bottled)
LLVM's OpenMP runtime library
https://openmp.llvm.org/
/opt/brew/Cellar/libomp/12.0.0 (9 files, 1.5MB) *

We see it installed it here:我们看到它在这里安装了它:

$ ls /opt/brew/Cellar/libomp/12.0.0/lib/
libomp.a    libomp.dylib

Make a simlink (based on the version of libomp you installed):制作一个 simlink(基于您安装的 libomp 版本):

$ mkdir -p /usr/local/opt/libomp/
$ ln -s /opt/brew/Cellar/libomp/12.0.0/lib /usr/local/opt/libomp/lib

Try importing it again.再次尝试导入。 This was able to resolve my issue.这能够解决我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM