importerror: cannot import name registermattype from cv2.cv2 error generates because of the incompatibility of opencv-python and opencv-python-headless. We should keep either of the same version or be compatible with each other. Usually this opencv-python-headless. package is for servers and opencv-python is suitable for desktop applications. Now
importerror: cannot import name registermattype from cv2.cv2 ( Cause ) –
As we have mentioned that this error is mainly coming because of the incompatibility of opencv-python and opencv-python-headless python package. But The most important thing is to understand how to check they are of different version. You may use this command to check the same.
pip list |findstr opencv
Basically, this command will print the version for all python module which has the prefix OpenCV. Here you can check the version difference. In the next section, we will explore how to fix this version difference.
importerror: cannot import name registermattype from cv2.cv2 ( Fix) –
The easiest fix for this error is to match either opencv-python version to opencv-python-headless version or vice versa. We can use the pip package manager to install any module for any of the versions.
pip uninstall opencv-python-headless pip install opencv-python-headless
pip uninstall opencv-python-headless pip install opencv-python-headless==version
Here this version should be equal to the version for opencv-python package.
There can be multiple scenarios to fix this problem.
- Either downgrade or upgrade to opencv-python package.
- We can also downgrade or upgrade to opencv-python-headless package ( Please refer to the above example)
- We can upgrade both to the latest version.
Using Conda for Fixing :
If you do not want to go with pip, You may use conda package manager to install and match the version for these packages. For example, If you want to upgrade both the package to the latest version using conda, Here is the command for this.
conda install -c fastai opencv-python-headless conda install -c conda-forge opencv
These tricks will surely resolve your bug. Go for it and make sure to check the version first before running any of the commands.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.