Skip to content
Related Articles

Related Articles

How to Install Scikit-Learn on MacOS?

View Discussion
Improve Article
Save Article
  • Last Updated : 30 Sep, 2021
View Discussion
Improve Article
Save Article

In this article, we will learn how to install Scikit-Learn in Python on MacOS. The scikit-learn is a Python module for machine learning built on top of SciPy and is distributed under the 3-Clause BSD license.

Installation:

Method 1: Using pip to install Scikit-Learn Package

Follow the below steps to install the Scikit-Learn 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 Scikit-Learn using pip3.

pip3 install scikit-learn

installing Scikit-Learn package on macOS using pip

Method 2: Using setup.py to install Scikit-Learn 

Follow the below steps to install the Scikit-Learn package on macOS using the setup.py file:

Step 1: Download the latest source package of Scikit-Learn for python3 from here.

curl https://files.pythonhosted.org/packages/e1/4d/15c3542a17eebf61e48bd71dc55b5f3b5031f1cd0dc4aad1ff9ac9651e49/scikit-learn-1.0.tar.gz > Scikit-Learn.tar.gz

downloading the source package for Scikit-Learn in macos

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

tar -xzvf Scikit-Learn.tar.gz

extracting the Scikit-Learn.tar.gz file in macos

Step 3: Go inside the folder and Enter the following command to install the package.

Note: Install Cython via pip before installing the module via setup.py

pip3 install Cython

installing cython via pip

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

cd scikit-learn-1.0
python3 setup.py install

installing Scikit-Learn on macOS using the setup.py file

Verifying Scikit-Learn installation on macOS:

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

import sklearn

Verifying Scikit-Learn installation on macOS

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!