三步在MacOS Anaconda安装ligthGBM
最近看了很多介紹在MacOS 安裝lightGBM包的文章,大部分都是Build from Source的方法,這個方法是之前唯一可行的方法,比較繁瑣,而且容易出錯。其實,現在安裝已經很簡單,只需要3步左右。
三步安裝ligthGBM
1. 安裝homebrew,建議通過國內鏡像來安裝,國外鏡像容易出現下載問題。
1)進入terminal終端(可通過 聚焦搜索 “終端”,點擊進入);
2)在終端輸入如下代碼(此為國內鏡像源);
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"3)會出現“開始執行Brew自動安裝程序”的命令,按照指示輸入 鏡像序號-->Y-->password(電腦開機密碼)即可安裝好HomeBrew。
?2. 使用homebrew安裝lightgbm
只需要一行代碼,在terminal中輸入
brew install lightgbm3. 安裝lightgbm的python版本
在Jupyter notebook中輸入
pip install wheel pip install lightgbm然后試試是否安裝好了
import lightgbm as lgbOK!
折騰歷史
1.比如下面這邊文章介紹得非常詳細:
MacBook Pro中安裝LightGBM的超詳細步驟 - 知乎
文中介紹的是Build from GitHub方法(文章使用國內鏡像來安裝homebrew,很快就成功了,我上次使用國際鏡像來安裝homebrew,文件下載一直出問題,折騰了很久)
但是到配置環境變量這個步驟時就出錯了。
3)構建算法依賴;
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.
對CMake編譯也不是很熟悉,這個問題就卡住了。
2. 然后去看了最新的官方文檔,Installation Guide — LightGBM 3.3.2.99 documentation
這里說一下:去看最新的官方文檔是一個非常好的解決問題的辦法,很多時候,很多算法包隨著系統的升級,安裝方法會越來約簡單,以前非常復雜的安裝過程,到后來就只需要一行代碼。
官方介紹的安裝lightgbm最簡單的方法是使用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一下,確實安裝好了
(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中導入lightgbm
import lightgbm as lgm提示錯誤信息:?
ImportError: No module named lightgbm查了一些文檔,說brew install lightgbm只是安裝了command line interface(CLI)版本的lightgbm,此時是不能直接在python中使用的,需要安裝python版本的lightgbm,即:
https://github.com/microsoft/LightGBM/tree/master/python-package#installation?
我在jupyter notebook中輸入了兩個命令:
pip install wheel pip install lightgbm然后在導入lightgbm,就可以了,大功告成!
總結
以上是生活随笔為你收集整理的三步在MacOS Anaconda安装ligthGBM的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CUKTECH 5 号彩虹电池发布:紫米
- 下一篇: 王者荣耀孤影孤立队友事件是怎么回事