安装后无法导入lightgbm

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

Thanks in advance for your help.

3个回答

6

4

我之前也遇到过这个问题。实际上,LightGBM依赖于OpenMP进行编译,而Apple Clang不支持。你需要使用以下命令安装gcc/g++:

brew install cmake
brew install gcc --without-multilib

请在此处查看更多细节。希望这能帮到您。


谢谢您的回复。我按照这里的说明进行操作:https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_LightGBM_for_Anaconda_on_MacOSX?lang=en 安装了lightgbm,并且我已经再次阅读了说明,似乎与上次我做的时候有一些变化。因此,也许我会卸载我的gcc并重新开始安装。 - Mike Gao

2

我遵循了网站上的安装指南(https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#macos)和(https://github.com/microsoft/LightGBM/issues/1369),因为我的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笔记本中后,它给出了安装libomp的警告,所以我也执行了以下命令:

brew install libomp

然后警告消失了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接