LightGBM安装

文章目录

  • 1. 参考文档
  • 2. Mac
  • 3. Linux

1. 参考文档

  • https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html
  • https://www.jianshu.com/p/ea248a74bf41

2. Mac

  1. 安装Mac依赖依赖:
→ brew install cmake
→ brew install libomp
  1. 终端下执行:
git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build

# For Mojave (10.14)
cmake \
  -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" \
  -DOpenMP_C_LIB_NAMES="omp" \
  -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" \
  -DOpenMP_CXX_LIB_NAMES="omp" \
  -DOpenMP_omp_LIBRARY=$(brew --prefix libomp)/lib/libomp.dylib \
  ..

# For High Sierra or earlier (<= 10.13)
cmake ..

make -j4
  1. 安装 lightgbm 包
→ pip install lightgbm

3. Linux

  1. 首先安装 cmake 。
sudo yum install cmake
→ sudo yum install gcc-c++

注意: 因为 Centos 默认安装的 gcc 是 4.4.7,所以安装过程汇总会提示 gcc 版本不够的错误。需要手动安装 gcc-7.3.0 版本,相关教程: https://blog.csdn.net/LuCh1Monster/article/details/94386322。安装好了 gcc-7.3.0 之后,在下面 cmake .. 这一步还是会报错,原因是还是会使用原先的 gcc 版本。

  1. 运行下面代码,进行安装:
git clone --recursive https://github.com/microsoft/LightGBM
→ cd LightGBM
→ mkdir build
→ cd build
→ cmake ..make -j4

在运行到 cmake .. 这一步时,出现报错:

[monster@centos build]$ cmake ..
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:22 (message):
  Insufficient gcc version

-- Configuring incomplete, errors occurred!

这是需要替换 gcc 版本:

export CXX=g++ CC=gcc

再次运行 cmake .. 就不会报错了,接下来运行 make -j4 就可以了。

  1. pip 安装 lightgbm
→ pip install lightgbm

你可能感兴趣的:(Python,LightGBM,专题,Python包使用)