This only installs Python 3.x bindings for OpenCV. – Adam Erickson Jul 4 '17 at 16:59 For installing on Python 2.x, remove the --with-python3 – Biranchi Jul 4 '17 at 17:29.
If you are still not able to install OpenCV on your system, but want to get started with it, we suggest using our docker images with pre-installed OpenCV, Dlib, miniconda and jupyter notebooks along with other dependencies as described in. Step 1: Install XCode Install XCode from App Store. If XCode available on App Store is not compatible with your OS:. Find XCode version compatible to your OS from this table. Go to this webpage. Login if you have apple developer account else create your account and login. Search for xcode and download the version compatible to your OS.
Install XCode. After installation open XCode, and accept xcode-build license when it asks. Step 2: Install Homebrew Launch a terminal from Launchpad. From this step onward, all commands will be run in the terminal. Ruby -e '$(curl -fsSL # update homebrew brew update # Add Homebrew path in PATH echo '# Homebrew' /.bashprofile echo 'export PATH=/usr/local/bin:$PATH' /.bashprofile source /.bashprofile # Homebrew recently moved popular formuale to homebrew-core # So this is not needed anymore to install OpenCV and you can skip this step. # tap science repo of home brew brew tap homebrew/science Step 3: Install Python 2 and Python 3 # If installing python for the first time using Homebrew, # else skip the 3 lines below and upgrade.
Brew install python python3 brew link python brew link python3 # NOTE: If you have python already installed using homebrew, # it might ask you to upgrade. # Upgrade the python using new homebrew formulae. Brew upgrade python brew upgrade python3 # Check whether Python using homebrew install correctly which python2 # it should output /usr/local/bin/python2 which python3 # it should output /usr/local/bin/python3 # Check Python versions python2 -version python3 -version Python version (2.6 or 2.7, 3.5 or 3.6) installed on your machine is required to determine path of Python’s site-packages.
It will be used later. NOTE: Recently Homebrew made some changes in Python formula. Earlier homebrew used to install python2 as /usr/local/bin/python. Now it follows these rules:.
Install python2 at /usr/local/bin/python2. Install python3 at /usr/local/bin/python3. python command will point to /usr/bin/python. This is the python distribution which comes with your OS and not installed by Homebrew. We want to use Python installed by Homebrew because it makes installing/managing packages easier. To run python scripts you should run command python2 and python3 for Python 2 & 3 respectively. If you find this annoying and want to use command python to run python2, add following line to /.bashprofile.
# Adding this line to end of.bashprofile will make python command # point to python2 export PATH='/usr/local/opt/python/libexec/bin:$PATH' This step is recommended not just for this course but in general to keep the python installation clean. Step 4: Install Python libraries in a Virtual Environment We will use Virtual Environment to install Python libraries.
It is generally a good practice in order to separate your project environment and global environment.
![Install Install](https://www.pyimagesearch.com/wp-content/uploads/2015/06/py3_opencv3_osx_compile_py_options.jpg)
By chance I just got this set up and working last week. Essentially it's three steps: Step 1.
Install OpenCV using Homebrew. The homebrew distribution used to be a bit finicky to get Python support, but as of a few months ago they simplified it down to a single precompiled distribution. Fortunately this includes Python 2/Python 3 support, ffmpeg support, and everything else you're likely to need. I do not advocate compiling OpenCV from source, it's a pain to get it configured and working. Also the version that Anaconda installs (conda install -c menpo opencv) had serious performance issues on my machine. The Homebrew version works well.
Install python on your computer by any method you want: Anaconda, Homebrew, etc. The Homebrew version of OpenCV is compiled to support Pythons 2.7 and 3.6 so you may as well install one of those, although other versions may work too. The key is you need to find the location of the site-packages directory for your python: Within the terminal start python, and at the interactive prompt do 'import sys' followed by 'print(sys.path)'.
(Without the quotes; I'll assume you have some knowledge of Python.) In the sys.path look for a directory path that contains 'site-packages'. Copy it down somewhere.
In the site-packages directory you found above, you'll need to put a symlink to the OpenCV library installed by Homebrew. By default this library is installed by Homebrew at a location like /usr/local/opt/opencv/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so So in the terminal you'll cd to the site-packages directory, and then execute 'ln -s /usr/local/opt/opencv/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so cv2.so' This will create a symlink called 'cv2.so' in site-packages. (It needs to have this name.) Step 4. Re-launch the python interpreter, and type 'import cv2'. If that works, type 'print(cv2.version)'.