Open In App

How to Install Opencv 4 on MacOS?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to install Opencv 4  in Python on MacOS. OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision.

Installation:

Method 1: Using pip to install Opencv 4 Package

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

pip3 install opencv-python

installing Opencv 4 package on macOS using pip

Method 2: Using setup.py to install Opencv 4

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

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

curl https://files.pythonhosted.org/packages/01/9b/be08992293fb21faf35ab98e06924d7407fcfca89d89c5de65442631556a/opencv-python-4.5.3.56.tar.gz > opencv.tar.gz

downloading the source package for Opencv 4 in macos

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

tar -xzvf opencv.tar.gz

extracting the opencv.tar.gz file in macos

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 opencv-python-4.5.3.56
python3 setup.py install

installing Opencv 4 on macOS using the setup.py file

Verifying Opencv 4 installation on macOS:

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

import cv2

Verifying Opencv 4 installation on macOS

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


Last Updated : 22 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads