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 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 
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

君宝bob

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值