Open In App

How to Install Matplotlib on MacOS?

In this article, we will learn how to install Matplotlib in Python on MacOS. Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python.

Installation:

Method 1: Using pip to install Matplotlib Package

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

pip3 install matplotlib

Method 2: Using setup.py to install Matplotlib 

Follow the below steps to install the Matplotlib package on macOS using the setup.py file:

Step 1: Download the latest source package of Matplotlib for python3 from here.

curl https://files.pythonhosted.org/packages/21/37/197e68df384ff694f78d687a49ad39f96c67b8d75718bc61503e1676b617/matplotlib-3.4.3.tar.gz > matplotlib.tar.gz

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

tar -xzvf matplotlib.tar.gz

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

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

cd matplotlib-3.4.3
python3 setup.py install

Verifying Matplotlib  installation on macOS:

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

import matplotlib 

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

Article Tags :