I have a Raspberry Pi running Raspian 10. I installed OpenCV using this tutorial. The steps seemed to all complete successfully, but I've had some problems importing the python module. When I use Python 3.7.3, I get the following output:
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
Which is clearly not working. Using Python 2.7.16 however, it runs fine:
>>> import cv2
>>> cv2.__version__
'4.6.0-dev'
Any idea why this may be? It seems like the OpenCV Python module isn't installed globally for Python 3. Ideally, I'd like to be able to use it in a Python 3 virtual environment.
I do have a temporary workaround. If I cd into the build directory containing the module, I can get it to work:
pi@raspberrypi:~ $ cd opencv/build/python_loader/
pi@raspberrypi:~/opencv/build/python_loader $ ls
cv2 setup.py
pi@raspberrypi:~/opencv/build/python_loader $ python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.6.0-dev'
Obviously, this isn't ideal.
pip3 install opencv-contrib-pythonto get all the modules.