Fixing Python Opencv error – QObject::moveToThread: Current thread (…) is not the object’s thread (…). Cannot move to target thread (…)

Python Opencv error – QObject::moveToThread: Current thread (…) is not the object’s thread (…). Cannot move to target thread (…) is an error which occurs because of a bug or because of a faulty opencv-python installation.

My goal today is to provide a clear and detailed explanation of why this error is happening and how to solve it, we will also check out other ways to get rid of this problem for good.

Exploring the Python Opencv error – QObject::moveToThread: Current thread (…) is not the object’s thread (…). Cannot move to target thread (…)

This is an error which occurs because of a bug or because of a faulty opencv-python installation.

Please check out the error message bellow and make sure you have the same message.

QObject moveToThread Current thread (…) is not the object’s thread (…)-problem-banner

I hope one of the solutions bellow will help you solve the problem and get rid of the error for good.

Solution 1 : Downgrade opencv-python

The most popular reason why the error occurs is a faulty opencv-python installation or a bug.

The perfect fix is to downgrade opencv-python. Please follow these step.

First, you should uninstall opencv-python

                                                                       #
# you should uninstall opencv-python like this
pip uninstall opencv-python
                                                                       #

Then you should use this command to see all the available versions

                                                                       #
# use this command to see all the available versions like this
pip install opencv-python==
                                                                       #

So, how do you know which option to choose ?

Easy, Start by trying the previous versions and then go down the list until your problem is gone, keep in mind that you have to repeat the process I am explaining until you solve the error.

As of now, we are at version 4.6.0.66. So, let us downgrade to version 4.5.5.64

                                                                       #
# let us downgrade the version like this
pip install opencv-python==4.5.5.64
                                                                       #

Try this command in Ubuntu.

                                                                       #
# use this command for Ubuntu.
sudo apt-get install python3-opencv
                                                                       #

The steps above should be enough to solve the error. If you tried all the steps and the error still persists, consider trying the method bellow.

Solution 2 : Solve the conflict between opencv-python and pyqt when you use Anaconda

Another reason why the error takes place is when you use a virtual environment in Anaconda and you install opencv-python and pyqt using the commands bellow

                                                                       #
# use a virtual environment in Anaconda and install opencv-python and pyqt
pip install opencv-python
# use a virtual environment to install pyqt
conda install pyqt
                                                                       #

Installing both pyqt and opencv-python installs two versions of PyQt, which causes a conflict.

To solve the conflict between opencv-python and pyqt you should uninstall both and then install PyQt5 like this.

                                                                       #
# install PyQt5 using this
pip install PyQt5
                                                                       #

After you do that, the error should be gone forever.

I hope the fixes above fixed your problem. Thank you for reaching the end of this article.

Summing-up : 

This is the end of our article, I hope the solutions I presented worked for you and solved the error : Python Opencv error QObject::moveToThread Current thread is not the object’s thread Cannot move to target thread

Learning Python is a fun journey, do not let the errors discourage you. Keep coding and cheers.

Thank you for reading my blog post to the end, If you want to learn more about the Python programming language, check out the official Python Documentation : https://docs.python.org/3/