VOOZH about

URL: https://www.geeksforgeeks.org/installation-guide/how-to-install-xgboost-and-lightgbm-on-macos/

⇱ How to Install XGBoost and LightGBM on MacOS? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Install XGBoost and LightGBM on MacOS?

Last Updated : 23 Jul, 2025

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.

Installation for XGBoost:

Method 1: Using pip to install XGBoost

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
👁 checking python and pip version in macos

Step 3: Upgrade your pip to avoid errors during installation.

pip3 install --upgrade pip
👁 upgrading pip in macos

Step 4: Enter the following command to install XGBoost  using pip3.

pip3 install xgboost
👁 installing XGBoost package on macOS using pip

Method 2: Using setup.py to install XGBoost (Recommended)

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
👁 downloading the source package for XGBoost in macos

Step 2: Extract the downloaded package using the following command.

tar -xzvf XGboost.tar.gz
👁 extracting the XGboost.tar.gz file in macos

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
👁 installing cmake using pip3

Note: You must have developer tools for XCode MacOS installed in your system

cd xgboost-1.4.2
python3 setup.py install
👁 installing XGBoost on macOS using the setup.py file

Verifying XGBoost installation on macOS:

Make the following import in your python terminal to verify if the installation has been done properly:

import xgboost
👁 Verifying XGBoost installation on macOS

If there is any error while importing the module then is not installed properly.

Installation for LightGBM:

Method 1: Using pip to install LightGBM 

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
👁 checking python and pip version in macos

Step 3: Upgrade your pip to avoid errors during installation.

pip3 install --upgrade pip
👁 upgrading pip in macos

Step 4: Enter the following command to install LightGBM using pip3.

pip3 install lightgbm
👁 installing LightGBM package on macOS using pip

Method 2: Using setup.py to install LightGBM (Recommended)

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
👁 downloading the source package for LightGBM in macos

Step 2: Extract the downloaded package using the following command.

tar -xzvf LightGBM.tar.gz
👁 extracting the LightGBM.tar.gz file in macos

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
👁 gcc and cmake installation using homebrew
👁 libomp installation using homebrew

Note: You must have developer tools for XCode MacOS installed in your system

cd lightgbm-3.2.1
python3 setup.py install
👁 installing LightGBM on macOS using the setup.py file

Verifying LightGBM installation on macOS:

Make the following import in your python terminal to verify if the installation has been done properly:

import lightgbm
👁 Verifying LightGBM installation on macOS

If there is any error while importing the module then is not installed properly.

Comment