How to Install Opencv 4 on MacOS?
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.
Method 1: Using pip to install Opencv 4 Package
Follow the below steps to install the Opencv 4 package on macOS using pip:
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 Opencv 4 using pip3.
pip3 install opencv-python
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-220.127.116.11.tar.gz > opencv.tar.gz
Step 2: Extract the downloaded package using the following command.
tar -xzvf opencv.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 opencv-python-18.104.22.168 python3 setup.py install
Verifying Opencv 4 installation on macOS:
Make the following import in your python terminal to verify if the installation has been done properly:
If there is any error while importing the module then is not installed properly.