How to Install XGBoost and LightGBM on MacOS? - GeeksforGeeks

18 Oct, 2021
In this article, we will learn how to install XGBoost and LightGBM in Python on macOS. XGBoost is an open-source software library that provides a regularizing gradient boosting framework for C++, Java, Python, R, Julia, Perl, and Scala.
LightGBM, short for Light Gradient Boosting Machine, is a free and open-source distributed gradient boosting framework for machine learning originally developed by Microsoft.
Follow the below steps to install the XGBoost package on macOS using pip:
Step 1: Install the latest Python3 in MacOS
Step 2: Check if pip3 and python3 are correctly installed.
python3 --version
pip3 --version
Step 3: Upgrade your pip to avoid errors during installation.
pip3 install --upgrade pip
Step 4: Enter the following command to install XGBoost  using pip3.
pip3 install xgboost
Follow the below steps to install the XGBoost package on macOS using the setup.py file:
Step 1: Download the latest source package of XGBoost for python3 from here.
curl https://files.pythonhosted.org/packages/cb/15/5a0e2977c2dca5dc374e6ba490674d7807d75e220b9bf2028d83a296d50f/xgboost-1.4.2.tar.gz > XGboost.tar.gz
Step 2: Extract the downloaded package using the following command.
tar -xzvf XGboost.tar.gz
Step 3: Go inside the folder and Enter the following command to install the package.
Note: Install cmake using pip3 before using setup.py to install xgboost
pip3 install cmake
Note: You must have developer tools for XCode MacOS installed in your system
cd xgboost-1.4.2
python3 setup.py install
Make the following import in your python terminal to verify if the installation has been done properly:
import xgboost
If there is any error while importing the module then is not installed properly.
Follow the below steps to install the LightGBM package on macOS using pip:
Step 1: Install the latest Python3 in MacOS
Step 2: Check if pip3 and python3 are correctly installed.
python3 --version
pip3 --version
Step 3: Upgrade your pip to avoid errors during installation.
pip3 install --upgrade pip
Step 4: Enter the following command to install LightGBM using pip3.
pip3 install lightgbm
Follow the below steps to install the LightGBM package on macOS using the setup.py file:
Step 1: Download the latest source package of LightGBM for python3 from here.
curl https://files.pythonhosted.org/packages/7a/6d/db0f5effd3f7982632111f37fcd2fa386b8407f1ff58ef30b71d65e1a444/lightgbm-3.2.1.tar.gz > LightGBM.tar.gz
Step 2: Extract the downloaded package using the following command.
tar -xzvf LightGBM.tar.gz
Step 3: Go inside the folder and Enter the following command to install the package.
Note: Install cmake, gcc, libomp using homebrew before using setup.py to install lightgbm
brew install cmake
brew install gcc
brew install libomp
Note: You must have developer tools for XCode MacOS installed in your system
cd lightgbm-3.2.1
python3 setup.py install
Make the following import in your python terminal to verify if the installation has been done properly:
import lightgbm
If there is any error while importing the module then is not installed properly.
how-to-install
Picked
How To
Installation Guide
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install FFmpeg on Windows?
How to Add External JAR File to an IntelliJ IDEA Project?
How to Set Git Username and Password in GitBash?
How to create a nested RecyclerView in Android
How to Install Jupyter Notebook on MacOS?
Installation of Node.js on Linux
How to Install FFmpeg on Windows?
How to Install Pygame on Windows ?
How to Add External JAR File to an IntelliJ IDEA Project?
How to Install Jupyter Notebook on MacOS?