直接
```bash
pip install lightgbm
```bash
mbpdeMacBook-Pro:~ mbp$ pip install lightgbm
Collecting lightgbm
Downloading https://files.pythonhosted.org/packages/a4/83/6e4a9cc870c117bf8316e8aa2513c5070f9ae2f8bd69469476414cd42595/lightgbm-2.3.0-py2.py3-none-macosx_10_8_x86_64.macosx_10_9_x86_64.macosx_10_10_x86_64.macosx_10_11_x86_64.macosx_10_12_x86_64.macosx_10_13_x86_64.macosx_10_14_x86_64.whl (678kB)
|████████████████████████████████| 686kB 14kB/s
Requirement already satisfied: scipy in ./anaconda3/lib/python3.6/site-packages (from lightgbm) (1.1.0)
Requirement already satisfied: numpy in ./anaconda3/lib/python3.6/site-packages (from lightgbm) (1.16.0)
Requirement already satisfied: scikit-learn in ./anaconda3/lib/python3.6/site-packages (from lightgbm) (0.19.1)
Installing collected packages: lightgbm
Successfully installed lightgbm-2.3.0
ok,看出来已经安装成功了,然后在python上加载lightgbm包;
```python
In [1]: import lightgbm
Traceback (most recent call last):
File "" , line 1, in <module>
import lightgbm
File "/Users/mbp/anaconda3/lib/python3.6/ctypes/__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/mbp/anaconda3/lib/python3.6/site-packages/lightgbm/lib_lightgbm.so, 6):
Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /Users/mbp/anaconda3/lib/python3.6/site-packages/lightgbm/lib_lightgbm.so
Reason: image not found
哭,加载失败,这都是报的什么鬼错误;
网上搜一下得到原因:主要是编译器的版本不一致(mac默认是gcc-8,pip安装的包则是用gcc-7编译的),但是我使用另外一种方法就完全不需要进行编译了。
再次安装libomp即可
```bash
mbpdeMacBook-Pro:~ mbp$ brew install libomp
==> Downloading https://homebrew.bintray.com/bottles/libomp-9.0.0.catalina.bottl
==> Downloading from https://akamai.bintray.com/9f/9fd9fde692bb74837400788a60ceb
######################################################################## 100.0%
==> Pouring libomp-9.0.0.catalina.bottle.tar.gz
/usr/local/Cellar/libomp/9.0.0: 9 files, 1.3MB
再次导入:
In [3]: import lightgbm as lgb
In [4]:
ok,大功告成。