安装lightgbm需要编译,mac的某些命令行指令又不是很熟,所以坑有点多。记录之~
1. 环境
- MAC: macOS High Sierra 10.13.4
- Python: python3.6
2. 安装lightgbm
2.1 homebrew安装
具体不赘述,参看博客http://www.cnblogs.com/lzrabbit/p/4032515.html
2.2 homebrew设置
homebrew有时候会很慢,可以做以下更改:
替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
重置brew.git:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
homebrew下载的软件在路径/usr/local/Cellar/
中
2.3 安装其他配置软件
安装编译相关的软件。
brew install cmake
brew install gcc --without-multilib
2.4 下载lightgbm
git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
在lightGBM文件夹里面创建build文件夹
mkdir build ; cd build
配置环境变量:
# add gcc
export PATH="/usr/local/Cellar/gcc/8.2.0/bin:$PATH"
在build
目录下,执行命令:
export CXX=g++-8 CC=gcc-8
注意版本一致,看前面的环境变量就好了。
官网是7,根据实际安装的情况,改下。
sudo cmake -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_C_COMPILER=gcc-8 ..
sudo管理员权限,执行编译命令。
sudo make -j4
下面执行以下命令,注意cd这一步实在build路径下执行的。
cd ../python-package
sudo python setup.py install --precompile
pip3 install lightgbm
3. REF
[1] https://blog.csdn.net/wgc7998/article/details/80302174
[2] https://blog.csdn.net/weixin_32087115/article/details/81489627
[1]就够了,写的比较详细
2018-11-23 于南京市栖霞区 紫东创意园