4

我的操作系统是 macOS Sierra,10.12.5,我使用的是 Anaconda 和 python 2.7。安装后,当我尝试时: import lightgbm as lgb 我收到以下消息:

OSError                                   Traceback (most recent call last)
<ipython-input-28-2ae3725bef24> in <module>()
----> 1 import lightgbm as lgb

/Users/tenggao/anaconda/lib/python2.7/site-packages/lightgbm/__init__.py in <module>()
      7 from __future__ import absolute_import
      8 
----> 9 from .basic import Booster, Dataset
     10 from .callback import (early_stopping, print_evaluation, record_evaluation,
     11                        reset_parameter)

/Users/tenggao/anaconda/lib/python2.7/site-packages/lightgbm/basic.py in <module>()
     29 
     30 
---> 31 _LIB = _load_lib()
     32 
     33 

/Users/tenggao/anaconda/lib/python2.7/site-packages/lightgbm/basic.py in _load_lib()
     24     if len(lib_path) == 0:
     25         raise Exception("cannot find LightGBM library")
---> 26     lib = ctypes.cdll.LoadLibrary(lib_path[0])
     27     lib.LGBM_GetLastError.restype = ctypes.c_char_p
     28     return lib

/Users/tenggao/anaconda/lib/python2.7/ctypes/__init__.pyc in LoadLibrary(self, name)
    438 
    439     def LoadLibrary(self, name):
--> 440         return self._dlltype(name)
    441 
    442 cdll = LibraryLoader(CDLL)

/Users/tenggao/anaconda/lib/python2.7/ctypes/__init__.pyc in __init__(self, name, mode, handle, use_errno, use_last_error)
    360 
    361         if handle is None:
--> 362             self._handle = _dlopen(self._name, mode)
    363         else:
    364             self._handle = handle

OSError: dlopen(/Users/tenggao/anaconda/lib/python2.7/site-packages/lightgbm/lib_lightgbm.so, 6): Library not loaded: /usr/local/opt/libiomp/lib/libiomp5.dylib
  Referenced from: /Users/tenggao/anaconda/lib/python2.7/site-packages/lightgbm/lib_lightgbm.so
  Reason: image not found

在此先感谢您的帮助。

4

3 回答 3

6

我在我的 Mac 上遇到了同样的问题,只需安装 OpenMP 库即可解决。

brew install libomp

如有任何疑问,请访问此处的安装页面

于 2019-11-29T11:55:09.220 回答
4

我以前和你一样有这个问题。实际上,LightGBM 依赖于 OpenMP 进行编译,Apple Clang 不支持。您应该使用以下命令安装 gcc/g++:

brew install cmake
brew install gcc --without-multilib

在此处查看更多详细信息 希望这可以帮助您。

于 2017-06-27T11:52:46.197 回答
2

我遵循了(https://github.com/microsoft/LightGBM/issues/1369)和网站上的安装指南(https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#macos

因为我有 gcc 版本 9.1.0,所以我使用了:

git clone --recursive https://github.com/Microsoft/LightGBM;cd LightGBM export CXX=g++-9 CC=gcc-9 mkdir build ; cd build cmake .. make -j4

在执行我的安装时,我运行:

pip install --no-binary :all: lightgbm

将 lightgbm 导入我的 jupyter notebook 后,它给了我安装 libomp 的警告,所以我也这样做了:

冲泡安装 libomp

然后警告消失了。

于 2019-11-12T23:31:01.433 回答