21

If I simply do:

import lightgbm as lgb

I'm getting

python script.py 
Traceback (most recent call last):
File "script.py", line 4, in <module>
import lightgbm as lgb
File "/usr/local/lib/python2.7/site-packages/lightgbm/__init__.py", line 8, in <module>
from .basic import Booster, Dataset
File "/usr/local/lib/python2.7/site-packages/lightgbm/basic.py", line 31, in <module>
_LIB = _load_lib()
File "/usr/local/lib/python2.7/site-packages/lightgbm/basic.py", line 26, in _load_lib
lib = ctypes.cdll.LoadLibrary(lib_path[0])
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 440, in LoadLibrary
return self._dlltype(name)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 362, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/python2.7/site-packages/lightgbm/lib_lightgbm.so, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/7/libgomp.1.dylib
Referenced from: /usr/local/lib/python2.7/site-packages/lightgbm/lib_lightgbm.so
Reason: image not found

I seem to have everything installed correct:

python -m pip install lightgbm
Requirement already satisfied: lightgbm in /usr/local/lib/python2.7/site-packages
Requirement already satisfied: wheel in /usr/local/lib/python2.7/site-packages (from lightgbm)
Requirement already satisfied: scikit-learn in /usr/local/lib/python2.7/site-packages (from lightgbm)
Requirement already satisfied: scipy in /usr/local/lib/python2.7/site-packages (from lightgbm)
Requirement already satisfied: numpy in /usr/local/lib/python2.7/site-packages (from lightgbm)

I do have a 6 folder in my GCC folder. Should I need to install another version of GCC for this to work?

enter image description here

4

8 回答 8

57

以上所有答案都对我不起作用。在 Mac 上,如果我使用 brew 安装了 libomp 解决了问题:参考:链接

brew install libomp
于 2019-05-02T18:32:29.933 回答
13

我在这里发现了一个类似的问题LightGBM
答案和评论可能会对你有所帮助。

在 Mac 中构建 LightGBM:

brew install cmake  
brew install gcc --without-multilib  
git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM  
mkdir build ; cd build  
cmake ..   
make -j  

然后安装:

cd ../python-packages  
sudo python setup.py install --precompile

正如@ecodan 所述,您可能需要强制 Mac 使用 GCC 和 G++ 而不是默认编译器。因此,不要使用 构建cmake ..,而是尝试:

cmake -DCMAKE_C_COMPILER=/usr/local/Cellar/gcc/6.1.0/bin/gcc-6 -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/6.1.0/bin/g++-6 ..

调整版本以匹配您的版本。

于 2017-07-07T09:57:16.657 回答
3

我在 M1 MAC 上遇到了同样的问题。我试图通过 Jupiter notebook 导入它。这个命令解决了这个问题:

conda install lightgbm
于 2022-01-18T16:56:06.200 回答
3

在 MAC 上,您需要安装 open-mpi:

brew install open-mpi
于 2018-04-24T20:17:48.527 回答
2

同样的错误,不同的来源:好像我安装了gcc 8版本,它需要 gcc 7。

它通过将其切换回最后一个 gcc 7 版本来工作:

brew switch gcc 7.3.0_1
于 2018-05-10T15:25:15.937 回答
1

在安装了 MacPorts 的 MacOS High Sierra 上,我执行了以下操作:

  1. clang-5.0使用 MacPorts安装
  2. /build目录中,运行 cmake -DCMAKE_CXX_COMPILER=clang++-mp-5.0 -DCMAKE_C_COMPILER=clang-mp-5.0 ..
  3. 要构建 python 包,请转到/python_package目录并修改setup.py脚本。您需要在compile_cpp()最后修改检查其他操作系统(包括 Mac)大小写的功能。在 之前silent_call(...),添加以下两行: cmake_cmd.append("-DCMAKE_CXX_COMPILER=clang++-mp-5.0") cmake_cmd.append("-DCMAKE_C_COMPILER=clang-mp-5.0")
  4. 运行sudo python setup.py install。享受
于 2018-02-09T01:40:19.487 回答
1

对于使用 macports 的用户,将 brew 解决方案的开头替换为:

  1. port install gcc7 cmake
  2. export CXX=g++-mp-7 CC=gcc-mp-7
于 2017-09-05T22:25:04.530 回答
0

我使用了从 PyCharm 生成的这个命令,它对我有用。

conda install -p { < =replace with USER_HOME_DIR>}/anaconda3 lightgbm -y

注意:我尝试了 Brew 和 pip install 但它们对我不起作用,因为 Azure ML 工作室已经下载了其他版本的 LightGBM,这些版本在升级到正确的软件包时会导致冲突。

于 2020-04-12T13:59:23.410 回答