-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImportError: cannot import name '_registerMatType' from 'cv2.cv2' #591
Comments
There is mess with versions:
Please ensure that you have installed one version of OpenCV only. |
yeah, uninstalling opencv-python and then reinstalling it with pip fixed this issue |
I solved this error on Google Colab by downloading the headless open-cv and of a version below 4.3 because backward compatibility was dropped since 4.3.0. Try the following command in Google Colab:
Here's a thread from stack overflow on the same issue. |
Thank you aQwus . It worked with !pip install "opencv-python-headless<4.3" |
Thanks @aQwus , that fixed it for me too! It's a little scary when your Colab code works one day and then stops working the next day 😬. |
@aQwus , thanks man that saved me to |
thank you very much, you save me! |
opencv-python-headless<4.3 is necessary to avoid `ImportError: cannot import name '_registerMatType' from 'cv2.cv2'` (see opencv/opencv-python#591 (comment)).
My problem was related to diferent versions of opencv modules. You can check it with: upgrading all modules to the same version solved my error:
|
@pjbelo You must not install all opencv-python types at once. You need to chose any one of them. |
Hi @abhiTronix. Thanks for your comment but I'm not sure if I understood it. I didn't install nothing new. Using |
@pjbelo Every OpenCV binary
You don't need all of them at once, just select any one of them according to your application. Installing all of them just going to overwrite previous binaries or cause more problem. Hope that helps. |
@abhiTronix I did not install any new packages. Using Google Colab and after installing TensorFlow Object Detection API I had these three packages installed: opencv-python, opencv-contrib-python, opencv-python-headless. Not sure why Google decided to to have them all installed or if they are not necessary. (you can check this here) I just updated their versions and that cleared the error. I'm aware that sometimes you need to have packages at a specific version (sometimes older versions) but I guess it was not my case because I got no errors. Just wanted to share this approach that might help someone else... |
Hi @abhiTronix , digging a bit deeper: After installing TensorFlow Object Detection API, this package is also installed: So the conflict between these packages must be the origin of the error. TensorFlow Object Detection API does not have a direct opencv dependency, as you can see here, so it must be a dependency of a dependency (is this the so called Hell of Dependencies?). So, following your reasoning the best solution would be to keep Anyway, updating all already installed packages to the same version also removed conflicts (and the error). Sorry about taking so much space here. I think this is not even an opencv issue, but a colab/dependencies config issue... |
Hi again @abhiTronix, digging a little bit deeper: This is the reverse tree of dependencies for colab / object-detection on opencv packages (at the moment of this comment): opencv-contrib-python==4.1.2.30 opencv-python==4.1.2.30
opencv-python-headless==4.5.5.64
As you can see, only How should a developer manage his list of dependencies? If package A depends on Should OpenCV take this in consideration and allow that all OpenCV packages could be installed at the same time avoiding conflicts? I know this does not make sense as direct dependencies, but considering the above case... I promise I have stopped my digging :-) |
I worked on a Nvidia Jetson container. There might be already cv2 beforehand. You could check with After I undo the installation of |
using cv2 on vscode i was having this problem but nothing worked. Turns out that i named my file as "cv2.py" so it was importing itself "Generally, the Python Circular Import problem occurs when you accidentally name your working file the same as the module name and those modules depend on each other. This way the python opens the same file which causes a circular loop and eventually throws an error." |
pip uninstall opencv-python-headless ; pip uninstall opencv-contrib-python ; pip uninstall opencv-python Then install only 1 of those 3. |
hats off to you brother! |
Probably you can manually delete the recursively duplidated cv2 foldres |
opencv-python-headless<4.3 is necessary to avoid `ImportError: cannot import name '_registerMatType' from 'cv2.cv2'` (see opencv/opencv-python#591 (comment)).
This way relly work! Thanks a lot! |
Trying to import cv2 in python 3.9.2 gives me the following error:
File "C:\Users\My Name\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2_init_.py", line 9, in
from .cv2 import _registerMatType
ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (C:\Users\My Name\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\cv2.cp39-win_amd64.pyd)
This is on Windows 10, with x86 architecture using opencv version (4.5.1.48)
The text was updated successfully, but these errors were encountered: