三步在MacOS Anaconda安装ligthGBM
最近看了很多介紹在MacOS 安裝lightGBM包的文章,大部分都是Build from Source的方法,這個(gè)方法是之前唯一可行的方法,比較繁瑣,而且容易出錯(cuò)。其實(shí),現(xiàn)在安裝已經(jīng)很簡(jiǎn)單,只需要3步左右。
三步安裝ligthGBM
1. 安裝homebrew,建議通過(guò)國(guó)內(nèi)鏡像來(lái)安裝,國(guó)外鏡像容易出現(xiàn)下載問(wèn)題。
1)進(jìn)入terminal終端(可通過(guò) 聚焦搜索 “終端”,點(diǎn)擊進(jìn)入);
2)在終端輸入如下代碼(此為國(guó)內(nèi)鏡像源);
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"3)會(huì)出現(xiàn)“開(kāi)始執(zhí)行Brew自動(dòng)安裝程序”的命令,按照指示輸入 鏡像序號(hào)-->Y-->password(電腦開(kāi)機(jī)密碼)即可安裝好HomeBrew。
?2. 使用homebrew安裝lightgbm
只需要一行代碼,在terminal中輸入
brew install lightgbm3. 安裝lightgbm的python版本
在Jupyter notebook中輸入
pip install wheel pip install lightgbm然后試試是否安裝好了
import lightgbm as lgbOK!
折騰歷史
1.比如下面這邊文章介紹得非常詳細(xì):
MacBook Pro中安裝LightGBM的超詳細(xì)步驟 - 知乎
文中介紹的是Build from GitHub方法(文章使用國(guó)內(nèi)鏡像來(lái)安裝homebrew,很快就成功了,我上次使用國(guó)際鏡像來(lái)安裝homebrew,文件下載一直出問(wèn)題,折騰了很久)
但是到配置環(huán)境變量這個(gè)步驟時(shí)就出錯(cuò)了。
3)構(gòu)建算法依賴(lài);
cmake ..
make -j4
cmake ..make -j4CMake Error: The source directory "/Users/feilong" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
make: *** No targets specified and no makefile found. Stop.
對(duì)CMake編譯也不是很熟悉,這個(gè)問(wèn)題就卡住了。
2. 然后去看了最新的官方文檔,Installation Guide — LightGBM 3.3.2.99 documentation
這里說(shuō)一下:去看最新的官方文檔是一個(gè)非常好的解決問(wèn)題的辦法,很多時(shí)候,很多算法包隨著系統(tǒng)的升級(jí),安裝方法會(huì)越來(lái)約簡(jiǎn)單,以前非常復(fù)雜的安裝過(guò)程,到后來(lái)就只需要一行代碼。
官方介紹的安裝lightgbm最簡(jiǎn)單的方法是使用homebrew,就一行代碼
brew install lightgbm很快也安裝好了
(base) feilong@bogon ~ % brew install lightgbm
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/libomp-13.0.0.catalina.bottle.
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/lightgbm-3.3.1.catalina.bottle
#=#=#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
curl: (22) The requested URL returned error: 404?
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/lightgbm/manifests/3.3.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/lightgbm/blobs/sha256:4b6a53e88126659be4d6c0a18e6d
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:4b6a53e8812665
######################################################################## 100.0%
==> Installing dependencies for lightgbm: libomp
==> Installing lightgbm dependency: libomp
==> Pouring libomp-13.0.0.catalina.bottle.tar.gz
🍺? /usr/local/Cellar/libomp/13.0.0: 9 files, 1.6MB
==> Installing lightgbm
==> Pouring lightgbm--3.3.1.catalina.bottle.tar.gz
🍺? /usr/local/Cellar/lightgbm/3.3.1: 98 files, 18.1MB
==> Running `brew cleanup lightgbm`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
然后check一下,確實(shí)安裝好了
(base) feilong@bogon ~ % brew list ==> Formulae ca-certificates gmp libevent lightgbm openssl@1.1 cmake hwloc libmpc mpfr zstd gcc isl libomp open-mpi?然后在jupyter notebook中導(dǎo)入lightgbm
import lightgbm as lgm提示錯(cuò)誤信息:?
ImportError: No module named lightgbm查了一些文檔,說(shuō)brew install lightgbm只是安裝了command line interface(CLI)版本的lightgbm,此時(shí)是不能直接在python中使用的,需要安裝python版本的lightgbm,即:
https://github.com/microsoft/LightGBM/tree/master/python-package#installation?
我在jupyter notebook中輸入了兩個(gè)命令:
pip install wheel pip install lightgbm然后在導(dǎo)入lightgbm,就可以了,大功告成!
總結(jié)
以上是生活随笔為你收集整理的三步在MacOS Anaconda安装ligthGBM的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: CUKTECH 5 号彩虹电池发布:紫米
- 下一篇: 正则表达式入门之字符匹配