How to Install XGBoost and LightGBM on MacOS?
Last Updated :
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.
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
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

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
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

Verifying XGBoost installation on macOS:
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.
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
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

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
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

Verifying LightGBM installation on macOS:
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.
Similar Reads
How to Install Lightgbm on Windows?
In this article, we will learn how to install Lightgbm in Python on Windows . LightGBM is a gradient boosting framework that uses tree based learning algorithms. It is designed to be distributed and efficient with the following advantages: Faster training speed and higher efficiency.Lower memory usa
2 min read
How to Install Java on Windows, Linux and macOS?
Java is a versatile programming language widely used for building applications. To start coding in Java, you first need to install the Java Development Kit (JDK) on your system. This article provides detailed steps for installing Java on Windows 7, 8, 10, 11, Linux Ubuntu, and macOS.Download and Ins
5 min read
How to Install LISP on MacOS?
Lisp is one of the oldest programming languages. It was invented back in the 1950s by John McCarthy. Lisp is a so-called meta-programming language or a symbolic programming language. It can be used for any sort of task. It's a general-purpose language. It is the second-oldest high-level programming
2 min read
How to Install Turbo C++ on MacOS?
Turbo C++ is a single-language compiler and integrated development environment. It is free of charge and can be downloaded from any website. The first release of Turbo C++ was released in May 1990 version 1.0, running on MS-DOS computers. For the C++ programming language, Turbo C++ is an integrated
4 min read
How to Install Lightgbm on Linux?
Lightgbm is an acronym for Light Gradient Boosting Machine. It is a machine learning framework based on decision tree algorithms. It is an open-source and free distributed gradient boosted model library. It is used for classification and other machine learning tasks. It is built by Microsoft Corpora
2 min read
How to Install Anaconda on MacOS?
In this article, we will learn how to install Anaconda on MacOS. Anaconda is a distribution of the Python and R programming languages for scientific computing, that aims to simplify package management and deployment. Installation using Graphical Interface Step 1: Download the Graphical installer fro
1 min read
How to Install C++ Libraries on MacOS?
C++ is a general-purpose object-oriented programming(OOP) language that was developed as an enhancement of the C language and that's why the basic syntax and code structure of both C and C++ are the same. C++ is a crucial and compiled language. C++ is a middle-level language used in developing drive
2 min read
How to Install Julia on MacOS?
Julia is one of the new programming languages that is becoming popular with time. It is used mainly for scientific data calculations and mathematical analysis. It is becoming popular because it has very fast execution like C and simple syntax like python. It is an open-source language with high perf
2 min read
How to Install Geopandas on MacOS?
In this article, we will learn how to install GeoPandas in Python on MacOS. GeoPandas is a project to add support for geographic data to pandas objects. Installation:Method 1: Using pip to install GeoPandas Follow the below steps to install the GeoPandas package on macOS using pip: Step 1: Install l
2 min read
How to Install Kotlin on MacOS?
Kotlin is an open-source programming language. It is developed by JetBrains and is designed to be a modern, safe, and efficient language for building modern applications. It is a functional language means it is based on the functional paradigm. It is a compiled language, which means it compiled to b
4 min read