26

Everything was running fine in Jupyter notebook until I imported Xgboost. 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?

---------------------------------------------------------------------------
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']
2
  • Solved I installed libomp.dylib for Mac OSX
    – jon
    May 23, 2020 at 12:27
  • Any idea how to do this on linux?
    – Wolfy
    Jan 12, 2021 at 20:13

8 Answers 8

38

I solved it by installing libomp.dylib for Mac OSX. The answer was there all along.

You can do it by running the following command :

brew install libomp

3
  • This fixed it for me too. Sep 3, 2020 at 23:21
  • 15
    agreed, and to be specific i did brew install libomp
    – user
    Sep 24, 2020 at 0:08
  • 1
    This didn't work for me on a M1 mac
    – jtb
    Feb 27, 2023 at 17:53
18

for Mac OSX, just run 'brew install libomp' enter image description here

1
  • The error message said that is an incompatible architecture (have 'arm64', need 'x86_64')). I think that it is still an unsolved issue for m1 mac users. btw, I had put the libomp.dylib to : /usr/local/opt/libomp/lib/libomp.dylib
    – Denny Chen
    Aug 9, 2022 at 17:36
12

If you use anaconda, you can use:

conda install py-xgboost
2
  • 4
    This worked for me on M1 Mac! No success even after brew install libomp Jan 29, 2022 at 2:33
  • Thanks for sharing! That solved it for me as well!
    – Timo
    Mar 1, 2022 at 9:24
9

The cause is that xgboost is looking for the dynamic library at the following locations, which is not where it might be installed to.

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.

After that, check where brew installed the library.

$ 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):

$ 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.

4

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

 

3

If brew install libomp doesn't work, libomp might be installed to a different place.

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. You can copy yours to the xgboost required path.

0
1

You can solve it as below if you have Python 3.7 or higher:

!brew install libomp
1

Below command worked for me if you are using anaconda

conda install -c conda-forge xgboost

Not the answer you're looking for? Browse other questions tagged or ask your own question.