importerror: cannot import name registermattype from cv2.cv2 (Fix It)

importerror_ cannot import name registermattype from cv2.cv2

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

or

pip uninstall opencv-python-headless 
pip install opencv-python-headless==version
importerror cannot import name _registermattype from cv2.cv2
importerror cannot import name _registermattype from cv2.cv2

Here this version should be equal to the version for opencv-python package.

There can be multiple scenarios to fix this problem.

  1. Either downgrade or upgrade to opencv-python package.
  2. We can also downgrade or upgrade to opencv-python-headless package ( Please refer to the above example)
  3. 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.

Thanks 

Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages Datasciencelearner.com, where he and his team share knowledge and help others learn more about data science.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner