mac lightgbm安裝

Mac LightGBM安裝坑較多,記錄:

一、安裝環境:

  • OS 10.13.6
  • virtualenv/python2.7
  • xcode 10.1
  • cmake 3.13.4
  • gcc 7.3

 

二、安裝實踐

1、brew install lightgbm,此方法不行,image not found錯誤

2、源碼編譯安裝

官網doc:https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#macos

源碼編譯安裝官網介紹有兩種方法:

  • Cmake + Apple Clang
1.Install CMake (3.12 or higher):
  brew install cmake

2.Install OpenMP:
  brew install libomp

3. Run the following commands:
  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

4.Install lightgbm
  cd ../python-packages  
  sudo python setup.py install --precompile

 

  • Cmake + gcc
1.Install CMake (3.2 or higher):
  brew install cmake

2.Install gcc:
  brew install gcc

3.Run the following commands:
  git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
  export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your 
  machine
  mkdir build ; cd build
  cmake ..
  make -j4

4.Install lightgbm
  cd ../python-packages  
  sudo python setup.py install --precompile

cmake環境如果沒設置,cmake命令加上參數:

cmake -DCMAKE_C_COMPILER=/usr/local/Cellar/gcc/7.3.0_1/bin/gcc-7 -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/7.3.0_1/bin/g++-7 ..

實踐版本爲cmake + gcc,經升級xcode、cmake,安裝OpenMP,解決問題。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章