Unable to import lightgbm after install

天大地大妈咪最大 提交于 2019-12-08 03:07:53

问题


My operating system is macOS Sierra, 10.12.5, and I am using Anaconda and python 2.7. After install, and when I try: import lightgbm as lgb I got the following message:

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.


回答1:


I had the issue as you before. Actually, LightGBM depends on OpenMP for compiling, which isn't supported by Apple Clang. You should install gcc/g++ by using following command:

brew install cmake
brew install gcc --without-multilib

See more details here Hope this can help you.




回答2:


I followed both (https://github.com/microsoft/LightGBM/issues/1369) and the installation guide from the website (https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#macos)

Since I have gcc version 9.1.0, I used:

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

in the implementation of my installation, then I ran:

pip install --no-binary :all: lightgbm

After importing the lightgbm into my jupyter notebook, it gave me the warning of installing the libomp, so I also did:

brew install libomp

Then the warning went away.




回答3:


I have encountered the same issue on my mac, which is fixed by simply installing OpenMP library.

brew install libomp

For any doubt please visit the installation page here



来源:https://stackoverflow.com/questions/44506921/unable-to-import-lightgbm-after-install

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!