QObject::moveToThread: Current thread (xx) is not the object‘s thread (xx).Cannot move to target

##异常: QObject::moveToThread: Current thread (xx) is not the object’s thread (xx).Cannot move to target

根源:

opencv要指定版本!!!
opencv 版本过高导致,试下这个: pip install opencv-python==4.1.0.25
原来是4.4,之前没有问题,conda安装matplotlib顺带安装了pyqt和qt,之后就显示这样的报错。我尝试卸载 matplotlib之后,4.4也不报错,应该是qt和pyqt这两个和其他的有什么冲突。但是需要matplotlib,没法卸载,尝试你的办法,降低opencv 的版本之后,问题解决。

opencv Ubuntu 安装

1. ubuntu18.04 python3.6 安装cv2 — opencv-python

$ pip install opencv-python==4.1.0.25  ## 推荐 指定版本一次成功,没有异常

$ pip3 install opencv-python  ## 这个方案一堆坑。
## 以下默认跳过不需要   如果遇到需要安装多个依赖异常,以下apptitude方案供参考
$ sudo apt-get install aptitude
$ sudo aptitude install libopencv-dev

2. 安装后检验cv2.版本,成功

	$ python3
Python 3.6.12 |Anaconda, Inc.| (default, Sep  8 2020, 23:10:56) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.5.1'

3. 接着调用,OpenCV 无法显示图像(能弹出黑框) 报以下异常:QObject::moveToThread: Current thread (xx) is not the object‘s thread (xx).Cannot move to target_第1张图片

   QObject::moveToThread: Current thread (xx) is not the object's thread (xx).Cannot move to target thread (xx)

3.1 问题原因分析及验证:

qt包未装好

解决方案尝试及结果:

a 方案1尝试, 失败

安装 pyqt :

 conda install pyqt

尝试结果: 失败

$ conda install pyqt
   Solving environment: | 
Warning: >10 possible package resolutions (only showing differing packages):
  - https://repo.continuum.io/pkgs/main/linux-64/linux-64::c-ares-1.17.1-h27cfd23_0, https://repo.continuum.io/pkgs/main/linux-64/linux-64::ld_impl_linux-64-2.33.1-h53a641e_7, https://repo.continuum.io/pkgs/main/linux-64/linux-64::libuuid-1.0.3-h1bed415_2, https://repo.continuum.io/pkgs/main/noarch/noarch::wcwidth-0.2.5-py_0
...
  ... and othedone
   All requested packages already installed.

如果比较慢的话,可以借助

pip install -i https://pypi.tuna.tsinghua.edu.cn/sample pyqt5

b 方案 安装OK,但是异常仍然存在。

## 参考安装qt 
https://blog.csdn.net/ChaoFeiLi/article/details/88418248

1.打开命令提示符输入:

pip3 install PyQt5 -i https://pypi.douban.com/simple

# 在这里选择豆瓣源的原因是下载速度较快,但并不是每次都能保证较高的下载速度。

2.安装PyQt常用工具

pip3 install PyQt5-tools -i https://pypi.douban.com/simple

4. 结论

opencv要指定版本!!!

 ## 推荐 指定版本一次成功,没有异常
$ pip install opencv-python==4.1.0.25 

你可能感兴趣的:(python,数字空间建设指南,深度学习,pytorch,神经网络,机器学习)