We already have a post for installing OpenCV 3 on Windows which covers how to install OpenCV3 from source for working with both C++ and Python codes. However, many readers have faced problems while installing OpenCV 3 on Windows from source. This post is for those readers who want to install OpenCV on Windows for writing Python code only.
Step 1: Install Anaconda (a python distribution)
Download and install Anaconda 64-bit version from https://www.continuum.io/downloads.
It is advised to install Anaconda for Python 3.
While installing Anaconda make sure that you check both options:
- Add Anaconda to my PATH environment variable
- Register Anaconda as my default Python
Step 2 : Create Virtual Environment
Open the command prompt and execute the following command.
conda create --name opencv-env python=3.6
You should get an output as shown below:
Press Enter and the environment will be installed and you should get an output as shown below :
Step 3 : Download and Install OpenCV
3.1. Download the pre-built binary
Open this link in a new tab. You should get a window as shown below :
Download the file named “opencv_python-3.3.1+contrib-cp36-cp36m-win_amd64.whl”. Note that it is for OpenCV 3.3.1 + contrib modules for python version 3.6 and windows with x64 architecture. If you have a 32-bit architecture, then download “opencv_python-3.3.1+contrib-cp36-cp36m-win32.whl”.
Keep in mind that this file may change when new versions of OpenCV come out.
3.2. Activate the environment
Change to the Download directory and execute the following commands.
cd C:\Users\YOUR_USERNAME\Downloads # See how the (opencv-env) appears before the prompt after this command. activate opencv-env
3.3. Install OpenCV and other important packages
Continuing from the above prompt, execute the following commands
pip install numpy scipy matplotlib scikit-learn jupyter pip install opencv_python-3.3.1+contrib-cp36-cp36m-win_amd64.whl pip install dlib
3.4. Test your installation
Open the python prompt on the command line by typing python on the command prompt
import cv2 cv2.__version__ import dlib dlib.__version__
You should get the following output
Subscribe & Download Code
If you liked this article, please subscribe to our newsletter. You will also receive a free Computer Vision Resource Guide. In our newsletter, we share OpenCV tutorials and examples written in C++/Python, and Computer Vision and Machine Learning algorithms and news.