OpenCV on Windows + Pip

I’ve had some minor issues with getting OpenCV to work on my Windows machine and all guides were not helping.

I was following these instructions found on OpenCV official website:

http://docs.opencv.org/3.2.0/d5/de5/tutorial_py_setup_in_windows.html

After installing python, numpy and matplotlib and trying to:

import cv2

I was greeted with the following error:

RuntimeError: module compiled against API version 0xa but this version of numpy is 0x7 windows

After some googling, the reason was quite obvious. I needed to upgrade my numpy version.

Somehow that appeared to be hard to do without Pip. How to get Pip

  1. Save this as get-pip.py https://bootstrap.pypa.io/get-pip.py
  2. Open up your cmd
  3. Type python get-pip.py
  4. You should be fine now
  5. To double check it’s indeed installed:
    1. Go to the location where your python and Scripts folder inside it C:\python27\Scripts
    2. You should see “pip” named .py file

After installing pip it should be very easy to get numpy installed.

pip install numpy

and to upgrade it to the latest version:

pip install numpy --upgrade

After which when I open my Python IDLE and write

import cv2
print cv2.__version__

I get no errors like the original tutorial said.

Leave a comment