Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am not able to run lightgbm on Mac because of an OSerror: libomp.dylib' (no such file)

Tags:

macos

lightgbm

I am not able to run lightbm on my MAC. I already tried all the solutions that I found but I can't get rid of the problem.

When I import lightgbm the following OSERROR appears:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Input In [2], in <cell line: 6>()
  4 from sklearn.metrics import accuracy_score
  5 import time
----> 6 from lightgbm import LGBMClassifier
  7 from xgboost import XGBClassifier
  8 print('make classification ...')

File ~/opt/anaconda3/lib/python3.9/site-packages/lightgbm/__init__.py:8, in <module>
  2 """LightGBM, Light Gradient Boosting Machine.
  3 
  4 Contributors: https://github.com/microsoft/LightGBM/graphs/contributors.
  5 """
  6 from pathlib import Path
----> 8 from .basic import Booster, Dataset, Sequence, register_logger
  9 from .callback import early_stopping, log_evaluation, print_evaluation, record_evaluation, reset_parameter
 10 from .engine import CVBooster, cv, train

File ~/opt/anaconda3/lib/python3.9/site-packages/lightgbm/basic.py:110, in <module>
106         raise LightGBMError(lib.LGBM_GetLastError().decode('utf-8'))
107     return lib
--> 110 _LIB = _load_lib()
113 NUMERIC_TYPES = (int, float, bool)
116 def _safe_call(ret: int) -> None:

File ~/opt/anaconda3/lib/python3.9/site-packages/lightgbm/basic.py:101, in _load_lib()
 99 if len(lib_path) == 0:
100     return None
--> 101 lib = ctypes.cdll.LoadLibrary(lib_path[0])
102 lib.LGBM_GetLastError.restype = ctypes.c_char_p
103 callback = ctypes.CFUNCTYPE(None, ctypes.c_char_p)

File ~/opt/anaconda3/lib/python3.9/ctypes/__init__.py:460, in LibraryLoader.LoadLibrary(self, name)
459 def LoadLibrary(self, name):
--> 460     return self._dlltype(name)

File ~/opt/anaconda3/lib/python3.9/ctypes/__init__.py:382, in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
379 self._FuncPtr = _FuncPtr
381 if handle is None:
--> 382     self._handle = _dlopen(self._name, mode)
383 else:
384     self._handle = handle

OSError: dlopen(/Users/pedropestana/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
  Referenced from: /Users/pedropestana/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so
  Reason: tried: '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/usr/local/lib/libomp.dylib' (no such file), '/usr/lib/libomp.dylib' (no such file).   

I already tried to reinstall the necessary libraries to install lightgbm but it still remains.

like image 914
Pedro Silva Avatar asked Jan 24 '26 19:01

Pedro Silva


1 Answers

For Linux users, glibc >= 2.14 is required. Also, in some rare cases, when you hit OSError: libgomp.so.1: cannot open shared object file: No such file or directory error during importing LightGBM, you need to install OpenMP runtime library separately (use your package manager and search for lib[g|i]omp for doing this).

For macOS (we provide wheels for 3 newest macOS versions) users:

Starting from version 2.2.1, the library file in distribution wheels is built by the Apple Clang (Xcode_8.3.3 for versions 2.2.1 - 2.3.1, Xcode_9.4.1 for versions 2.3.2 - 3.3.2 and Xcode_10.3 from version 4.0.0) compiler. This means that you don't need to install the gcc compiler anymore. Instead of that you need to install the OpenMP library, which is required for running LightGBM on the system with the Apple Clang compiler. You can install the OpenMP library by the following command: brew install libomp.

-- LightGBM Python-package docs

tl;dr: for mac, brew install libomp

like image 177
Amadan Avatar answered Jan 26 '26 11:01

Amadan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!