The Error “Cannot import name ‘_registerMatType’ from ‘cv2.cv2′” happens because the version of the opencv-python and opencv-python-headless packages are not compatible. So to fix this Error, you have to install the opencv-python and opencv-python-headless packages with the same version. Let’s learn more about it with the explanation and example below.
How Does This Error Occur?
The Error “Cannot import name ‘_registerMatType’ from ‘cv2.cv2′” happens because the version of the opencv-python and opencv-python-headless packages are incompatible. So, when you run the project of The Object Detection API, you will get an Error like this.
You can check the version of the opencv-python and opencv-python-headless packages by running the following command.
pip list |findstr opencv
If these versions are not the same, an Error will occur when you work with the opencv packages.
Solve The Error “Cannot import name ‘_registerMatType’ from ‘cv2.cv2′” in Python
To fix this Error, you can reinstall the opencv-python and opencv-python-headless packages but sometimes, it is not useful. Another effective solution is installing the opencv-python and opencv-python-headless packages with the same version. Let’s learn more about it in the next title below.
Install the opencv-python and opencv-python-headless packages with the same version
To fix this Error, you have to uninstall the current opencv-python and opencv-python-headless packages first by running the following command.
pip uninstall opencv-python-headless
pip uninstall opencv-python
Then, you reinstall the opencv-python and opencv-python-headless packages with the same version by running the following command.
pip install opencv-python==version
pip install opencv-python-headless==version
After doing that, the Error will be fixed.
Fix this Error in Jupyter Notebook or Google Colaboratory
Same with the first method, you have to uninstall the current opencv-python and opencv-python-headless packages first by running the following command.
!pip uninstall opencv-python-headless
!pip uninstall opencv-python
Then, you reinstall the opencv-python and opencv-python-headless packages with the same version by running the following command.
!pip install opencv-python==version
!pip install opencv-python-headless==version
Summary
We have shown you how to solve the Error “Cannot import name ‘_registerMatType’ from ‘cv2.cv2′” in Python. This Error occurs when you are using the opencv-python and opencv-python-headless packages with the not same version. To fix this Error, you have to reinstall the opencv-python and opencv-python-headless packages with the same version. Choose the solution that is best for your environment. If you have any questions about this tutorial, leave your comment below, and I will answer your questions. Thanks!

My name is Thomas Valen. As a software developer, I am well-versed in programming languages. Don’t worry if you’re having trouble with the C, C++, Java, Python, JavaScript, or R programming languages. I’m here to assist you!
Name of the university: PTIT
Major: IT
Programming Languages: C, C++, Java, Python, JavaScript, R