Solving python tensorflow ImportError: cannot import name ‘_registerMatType’ from ‘cv2.cv2’

Python tensorflow ImportError: cannot import name ‘_registerMatType’ from ‘cv2.cv2’ is an error which occurs because of a faulty opencv installation or a missing opencv dependency.

In today’s article I am going to deal with a confusing error and explain why it takes place and how to fix it, with a set of possible solutions.

Exploring the python tensorflow ImportError: cannot import name ‘_registerMatType’ from ‘cv2.cv2’

This is an error which occurs because of a faulty opencv installation or a missing opencv dependency.

Please make sure the error message looks like the error message bellow after double checking. Do not mix between errors.

                                                                       #
ImportError: cannot import name '_registerMatType' from 'cv2.cv2'
                                                                       #

Bellow, I have a couple of methods that might solve the issue for you.

Solution 1 : use -upgrade opencv-contrib-python and -upgrade opencv-python-headless

Your best shot at solving the problem is following the step by step instructions bellow.

First, you should upgrade opencv-python-headless using the command bellow

                                                                       #
python -m pip install --upgrade opencv-python-headless
                                                                       #

Then, you should upgrade opencv-contrib-python like this

                                                                       #
python -m pip install --upgrade opencv-contrib-python
                                                                       #

I hope this method has solved the issue for you. Try the method bellow if this one fails.

Solution 2 : Correctly use conda-forge opencv and conda-forge opencv-contrib-python and more.

This method is only for those who have conda or those who want to use it.

You should use conda forge to install opencv and opencv-contrib-python

                                                                       #
conda install -c conda-forge opencv=4.6.0
                                                                       #

Install opencv-contrib-python like this

                                                                       #
conda install -c conda-forge opencv-contrib-python=4.6.0
                                                                       #

You can also try installing opencv-python-headless like we did in the first method

                                                                       #
conda install -c conda-forge opencv-python-headless
                                                                       #

I hope this guide solved your problem, thank you for reading this blog post to the end.

Summing-up : 

Consider donating to my Kofi account if you want to help me and my website.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/