The following instructions only apply to Mac OSX users.
Make sure you have the following before starting:

  • Internet connection
  • Mac OSX Command Line tools
  • Terminal

If you do not have Mac OSX Command Line Tools installed, go to Create an account and then go to the Mac Developer section to find the individual .dmg file for MAC CLT. Another options would be to install Xcode and then install Mac OSX Command Line Tools via the setup process or by going into the settings and installing the add-ons needed.

These are dumb step by step instructions of how to get Python (2.x.x) and OpenCV (2.4.x) on your Mac OS (personally tested for 10.8-10.9). In this setup we will be using homebrew over the official Python API and or Macports because homebrew sand-boxes all the things that it installs so that if you somehow mess up, removing them will be easy because it won’t be system wide.

1. Install homebrew

Copy paste this to terminal

"ruby -e "$(curl -fsSL""

It will take about a minute to install depending on your CPU speed and internet speed. After the process stop running and you are returned to an open line again, run

“brew doctor” to check that everything has been installed correctly.

2. Install Python

Type into a new terminal line

“brew install python”

This will install the latest version of Python 2.7.x available. Python 3.x.x is available as well but not recommended as it does not work well with OpenCV. When installing Python it will also install “pip” which is a tool used later on to install numpy.

3. Fix your $PATH Variable

This is needed so that your system Python is the same as that of the one install by Homebrew. Type into terminal

“sudo nano /etc/paths”

Manually delete everything and then copy paste the following lines in the same order.







Hold down control and press ‘X’ then press ‘Y’ then press enter to save the newly edited PATH file.

4. Install numpy

type into a new line of terminal

“pip install numpy”

Wait until it finishes installing and brings you to a new line.

5. Random problem OSX Mavericks only

For some reason OpenCV doesn’t install on 10.9 Mavericks straight out like in the other versions so you have to go to a new line in terminal and enter

“cd /usr/local”


“git reset –hard 0313168fc9287710c22e792c5581cd545ae52b59″

There will be a few lines of response, wait till new line of terminal.

6. Install OpenCV 2.x.x

For the purposes of this tutorial I will be installing OpenCV 2.4.5 because that is what I need. If you are new to opencv then you can just install the latest version of OpenCV by typing in 

“brew tap homebrew/science”

Let that clone the directories. Then enter

“brew install opencv”

For those who are looking for a specific version of OpenCV, type

“brew tap homebrew/science”

Let that clone the directories. Then enter

“brew versions opencv”

This will list out all the versions available for download. For example:  git checkout d160807 opencv.rb  git checkout ebc5b15 opencv.rb  git checkout 9c5be73 opencv.rb

2.4.5    git checkout ae74fe9 opencv.rb

2.4.4a   git checkout 3efa797 opencv.rb

2.4.4    git checkout d85d011 opencv.rb


Go to the version that you want. In my case it is 2.4.5 and copy the statement AFTER it. So in my case, I would copy “git checkout ae74fe9 opencv.rb” Then enter on a new line of terminal

“cd /usr/local/Library/Homebrew”

Now Enter

“git checkout ae74fe9 opencv.rb”

At this point OpenCV (your version) should start installing. It’s a big file so give it time and at the end it will be fully installed! You can check by opening a new terminal windows, typing “python” to enter the python interpreter and then typing “import cv2″. If it is installed correctly then it will just move on to a new line but if not then you will receive error messages. Good luck!

Additional Notes for Sublime Users

In order to get sublime to use the system’s python which has access to the OpenCV so that you can build the file within the app itself, do the following.

Navigate to your Library folder (If you don’t have access google how to see invisible folders on the mac or get an app called Revealer)

Navigate the following system path Library/Application Support/Sublime Text 2/Packages/Python

In that folder you will find a folder called “Python.sublime-build” Open it with sublime and then replace the content with the following:

    "path" : "/usr/local/bin:/usr/bin:/usr/sbin/:/bin:/sbin",
    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"

Save the file and then you’re good to go!