mac上的lightgbm

安装lightgbm

  • 详细的安装步骤参见lightgbm官方文档的安装指南

  • 首先安装Homebrew(一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。已经安装可直接跳过。)

    • 进入Homebrew官网
    • 如图所示,复制官网红框的代码在shell中运行即可安装Homebrewmac上的lightgbm_第1张图片
  • 在shell中输入命令行,安装libmop

brew install libomp
  • 使用命令行直接从pypi下载
pip install lightgbm

报错

  • 运行报错如下:

OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/

解决方法一

  • 根据报错信息OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialized.提示,可能是libiomp5.dylib的存在导致错误。
  • 转到anaconda3/lib目录下,
cd /anaconda3/lib/
  • 移除libiomp5.dylib文件,此时程序可以正常运行。

解决方法二

  • 根据报错信息As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute,提示,将KMP_DUPLICATE_LIB_OK设置为TRUE。
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
  • 此时程序可以正常运行。

官方文档

你可能感兴趣的:(踩的坑)