5

I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. I am running this on a Windows machine.

When I write import cv3 at the top of my code, it returns the error ImportError: No module named 'cv3'

I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3 in the Command Prompt. It is apparently already installed because it returned

Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3       3.1.0       py35_0      https://conda.binstar.org/menpo

Am I importing cv3 wrong? How do I fix this error?


Update: Tried import cv3 instead of import cv2 but got the following error: ImportError: cannot import name 'cv2'. The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. Any ideas?

J. Doe
  • 338
  • 2
  • 4
  • 9

4 Answers4

21

Ironically enough, the module is still called cv2 because it doesn't represent the version of opencv but the actual C++ API underneath which is, to be contrasted from the C API, named - cv2... So try with: import cv2

zwer
  • 24,943
  • 3
  • 48
  • 66
  • When I tried `import cv2` I got the error `ImportError: cannot import name 'cv2'`. Which is different wording from the other error, but still does not work for some reason. – J. Doe May 21 '17 at 23:45
  • Hmmm... then it appears that it was badly installed. Apart from bad compiling, I'm guessing it was installed in a subfolder of a subfolder cv2 as it commonly happens, try `import cv2.cv2`. If it doesn't solve it, try checking where in the `site-packages` of your Python env. it picks it from. – zwer May 22 '17 at 00:01
2

Problem solved by using command pip uninstall opencv-python in the Command Prompt.

I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. I looked into the build of some of the other installations I attempted and some were for Python 2.7. Maybe that contributed to the error.

Thankfully, this worked. Now import cv2 works perfectly. No errors.

J. Doe
  • 338
  • 2
  • 4
  • 9
1

I used the same approach to install the package. However, I could not import the library using the name opencv3. I had to use cv2 which worked for me.

Christian Dean
  • 22,138
  • 7
  • 54
  • 87
Lumbreras
  • 36
  • 7
0

Elaborating on @zwer's answer, check the version of OpenCV after import cv2.

>>> cv2.__version__
'3.1.0'

So basically it's calling the OpenCV3 library.

Harsh Wardhan
  • 2,110
  • 10
  • 36
  • 51