How to Install OpenCV on M1 Mac using pip

Apple’s M1 chip is powered by Apple’s in-house developed chip, which has improved the processing speed compared to previous Macbook products. However, unlike previous models that had Intel chips, the M1 is Apple’s in-house developed chip, so there is a problem that unsupported libraries cannot be installed. Therefore, this article will show you how to easily install OpenCV libraries on a Macbook with M1 chip.

Operating System and Python Version

  • macOS Monterey Version 12.0.1 on Macbook Air (M1, 2022)
  • Python 3.9.5
  • zsh on iTerm

Steps to Install OpenCV on M1

Check the current architecture of M1 Mac.

If the CPU architecture is the default, it should return “arm64”.

Here is the KEY! Then, change the CPU architecture by putting the following command!

Next, create a virtual environment on Terminal (iTerm).

Then, activate the virtual environment.

After everything is set up, install the OpenCV on M1 Mac! You can simply follow the command below, and more detail of the OpenCV using pip is from here.

Numpy is also installed during installing opencv-python. When you type “pip list” on Terminal, you should be able to see the image like below.

Installation of OpenCV on M1 is basically done. Let’s confirm the library itself can import from a script. In order to confirm it, you can just type python3 in the virtual environment on Terminal (an interactive mode). Then, type “import cv2”. If you would like to exit from the interactive mode, just type “exit()”.

Execute a Python script

Once the installation is confirmed in the interactive mode, let’s program a Python script by importing an OpenCV library in the script mode. The following Python is simply executing a built-in camera of M1 Mac.

Finally, execute the script above! You should be able to open the built-in camera on M1 Mac!

That is all! I hope this tutorial helps you out.

Related Post

Leave a Reply

Your email address will not be published.

CAPTCHA