import cv2 works but import cv2.cv as cv not working

xdan picture xdan · Sep 6, 2012 · Viewed 8.7k times · Source

I think the sys path is correct, cv.pyd and cv.pyd reside in c:\OpenCV2.3\build\Python\2.7\Lib\site-packages.

>>> import sys
>>> sys.path
['', 'C:\\Python27\\Lib\\idlelib', 'C:\\Python27\\lib\\site-packages\\pil-1.1.7-py2.7-win32.egg',     'C:\\Python27\\lib\\site-packages\\cython-0.17-py2.7-win32.egg', 'C:\\Python27\\lib\\site-packages\\pip-1.2-py2.7.egg', 'c:\\OpenCV2.3\\build\\Python\\2.7\\Lib\\site-packages', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\IPython\\extensions']

And import cv or cv2 seems to be ok but import cv2.cv not

>>> import cv
>>> import cv2.cv as cv

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    import cv2.cv as cv
ImportError: No module named cv
>>> import cv2
>>> cv.NamedWindow("camera", 1)

...

What could be the reason of the ImportError?

Answer

SivamNatesan picture SivamNatesan · Jun 30, 2016

I had the same issue.This was an issue with OpenCV Engine.Download OpenCV engine from https://github.com/thumbor/opencv-engine/releases/tag/1.0.1 and save it as engine.py in \Python27\Lib\site-packages.use cv2.cv instead of cv2.cv as cv.