In this post, I am going to tell you how to install OpenCV on your Mac OSX, so that you can import cv in your python code. In my case, I’ll be installing OpenCV 2.4.12 and running python 2.7 on my Mac OSX. The version of OpenCV will keep updating, so in the following procedure you might need to change the version number. Otherwise, there might be some errors installing.
Let’s get started.
Step 1. Install Homebrew.
Homebrew includes some packages that Mac OSX doesn’t include, so it is better to install Homebrew and get the extra packages. This is the link to install Homebrew:
In this website, the only thing that you’ll need to do is to copy the code below:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Go to your terminal, then type “bash” and press enter.You’ll be now using bash shell to install Homebrew.
Now paste the code that you just copy and press enter. It should start to install Homebrew. You’ll need to type your password while installing.
Step 2. Install OpenCV on your Mac OSX.
The following procedure is followed by the website here:
In case you have any problem installing, remember to go to the website and check the details.
Under the bash shell, copy and paste the code below and enter:
brew tap homebrew
Then copy and paste the code below and enter:
You can find your OpenCV at the code below. OpenCV will keep updating its version, so you might need to change the number of version rather that “2.4.12”.
Step 3. Setting up python
Go to your python path by typing the code below:
Go to the package folder of python: (If you are not using python 2.7, you might also need to change the number of version)
Create a symlink by typing the code below, and you’ll need to type “sudo” beforehand to run the code as a administrator. Later on type you’ll password to run. You might also change the number of version in the code below.
Type and run the code below:
Congratulations! You are done!
Step 4. Check if your Mac OSX can import OpenCV
Run the python by merely typing python:
You’ll see something similar like this.
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Now, you are running python on your terminal. Run the code below and see if OpenCV successfully be installed.
If there is no error pop out, then you had completely installed.
There is an error when I am installing OpenCV. The terminal says that one of my packages is not up to date, so I’ll need to first upgrade the package. In my case, the numpy is not the latest version. You should change “numpy” to other package name.
pip install numpy --upgrade
After that, you should be able to install OpenCV on your Mac OSX.
Feb 23, 2016