Ask Your Question
0

Import Error: cannot import name 'cv2'

asked 2017-07-10 14:57:22 -0600

KK gravatar image

I want to begin exploring OpenCV in Python but I'm stuck at importing the package cv2. I have installed the package through pip3 install opencv-python and it got installed at this location - C:/Users/Kshitiz/AppData/Local/Programs/Python/Python36-32/Lib/site-packages.

When I'm trying to import cv2 using this:

import sys
sys.path.append('C:/Users/Kshitiz/AppData/Local/Programs/Python/Python36-32/Lib/site-packages')
import cv2

It gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:/Users/Kshitiz/AppData/Local/Programs/Python/Python36-32/Lib/site-packages\cv2\__init__.py", line 7, in <modul
e>
    from . import cv2
ImportError: cannot import name 'cv2'

I have searched a lot but cannot find anything relevant. Please suggest what needs to be done. Thanks.

edit retag flag offensive close merge delete

Comments

From https://pypi.python.org/pypi/opencv-p... :

Q: Import fails on Windows to some DLL load error?

A: If the import fails on Windows, make sure you have Visual C++ redistributable 2015 installed. If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.

See also this issue if you are using Anaconda.

Q: I have some other import errors?

A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages).

LBerger gravatar imageLBerger ( 2017-07-10 15:30:15 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-05-23 07:52:02 -0600

Hayley gravatar image

When I try to call python script in java by jython, the following error occured, just like what happened to you. Have you worked it out?

Exception in thread "main" Traceback (most recent call last): File "D:\WorkSpace\PyCharmProjects\python_opencv\readImg.py", line 3, in <module> import cv2 File "D:\Installation\Anaconda3\Lib\site-packages\cv2__init__.py", line 7, in <module> from . import cv2 ImportError: cannot import name cv2

edit flag offensive delete link more
0

answered 2017-10-24 06:03:21 -0600

Python27 that I have installed in my Windows 10 environment is compatible only with X86 version of CV2. So, I copied cv2,pyt from C:\OpenCV\build\python\2.7\x86 to python24/Lib/ and then ran python24 idle.

install cv2 worked!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-07-10 14:57:22 -0600

Seen: 5,465 times

Last updated: Jul 10 '17