mac os 上安装lightgbm 采坑

直接


```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 "<ipython-input-1-b18b3f8a6dc8>", 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,大功告成。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值