ImportError: No module named cv2

47,751

Solution 1

The fastest and cleanest way is to run pip. It's a clean convenient tool for Python packages.

Just run:

pip install opencv-python or C:\Python27\Scripts\pip.exe install opencv-python

Solution 2

The easiest way to install OpenCV on Windows is to simply copy the cv2.pyd file into Python's site-packages directory (e.g. C:\python27\Lib\site-packages).

To get the cv2.pyd file, download and extract the latest version of the OpenCV installation executable from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/ and browse the extracted folder to find the file in the relevant build directory (e.g. build\python\x86\2.7).

Share:
47,751
Shatil Haque
Author by

Shatil Haque

Updated on July 09, 2022

Comments

  • Shatil Haque
    Shatil Haque almost 2 years
    import numpy as np
    
    import cv2
    from matplotlib import pyplot as plt
    
    img = cv2.imread('1.jpg',0)
    
    orb = cv2.ORB()
    
    kp = orb.detect(img,None)
    
    kp, des = orb.compute(img, kp)
    
    
    img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
    plt.imshow(img2),plt.show()
    

    In here, I have installed numpy and opencv in my windows operating system. But i can't find out the proper way to add cv2 module.

  • Shatil Haque
    Shatil Haque over 8 years
    I've also copy cv2.pyd file into site-packages, but now there occurring a new error. "ImportError: DLL load failed: The specified module could not be found." @figs
  • 101
    101 over 8 years
    That could be related to something else, e.g. importing numpy or matplotlib. Try a much simpler script that only imports cv2. Also check out this related answer: stackoverflow.com/questions/22221427/…