5

I am trying to use OpenCV for Python 3 for the first time. To install, I simply typed pip3 install opencv-python into the terminal. When I do this, I see in Finder (I'm on a Mac), that in /usr/local/lib/python3.7/site-packages, I now have a new folder called "cv2".

This is strange. Why isn't it cv3, as I used pip3? I do not know.

When I try to import cv2 from python3, it says No module named 'cv2'. Luckily StackOverflow already has a solution: if I first change directories like:

cd /usr/local/lib/python3.7/site-packages

then I will be able to open cv2. I do not know why this step is necessary for OpenCV. I don't have to do this to import numpy for example; numpy does not care what directory I start from, and it is listed like just another module like cv2.

Anyways, I change directory to site-packages, start python3, and I import cv2. Now there is a new error. This time cv2 is found, but it says:

from .cv2 import *  
ModuleNotFoundError: No module named 'cv2.cv2'

For the record, I also have Python 2.7. If I try cd /usr/local/lib/python2.7/site-packages and then start Python 2.7, I can import cv2. This is ok, but I want to use OpenCV with Python3.

Let me summarize.

(1) How can I get cv2 or cv3 to import when I start from any directory? Is this ever possible?

(2) How can I get cv3 for python3? cv2 seems to be problematic in python3 because because there is no cv2.cv2

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36

3 Answers3

3

The only thing we need to know here is, that 2 in cv2 is not a version. cv2 uses API of C++ while cv uses C API. Version of it is constantly updating being inside CV2.

0

There is no "cv3".

"cv2" stands for the API version, not the library version.

API Version 1 was for C (and Python). API version 2 is C++ (and Python).

API Version 2 exists since library version 2.0.

API Version 1 was removed step by step throughout library version 3.x. It is no longer available in library version 4.0.

If you installed the package but your Python can't import cv2 as cv (the officially recommended import statement), then you either installed the package into a virtual environment or you have multiple pythons and you installed it in a different python from the one you're trying to import it into.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
-1

There is no cv3 there's only import cv2 that opencv older or latest that is updated for old python or latest.

Ram
  • 1
  • 1