qt和opencv应用程序在虚拟环境中不工作

n9vozmp4  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(469)

我使用pyqt5和opencv创建了一个gui应用程序。应用程序在不激活虚拟环境的情况下工作正常,但当我激活虚拟环境并运行应用程序时,它会显示以下错误:

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

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/deepak/Desktop/SampleApp/lib/python3.9/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.

Aborted

我尝试运行一个示例pyqt5代码(不导入opencv)和另一个代码(仅使用opencv),这两个代码在虚拟环境中都运行良好。
操作系统:parrot os 4.11
python版本:3.9.2

b91juud3

b91juud31#

问题在于编译opencv时使用的qt版本与pyqt5使用的版本不同,从而导致冲突。
一个可能的解决方案是指示使用pyqt5使用的qt插件。

import os
from pathlib import Path

import PyQt5
from PyQt5.QtWidgets import QWidget # others imports
import cv2

os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.fspath(
    Path(PyQt5.__file__).resolve().parent / "Qt5" / "plugins"
)

# ...

对于pyside2:

import os
from pathlib import Path

import PySide2
from PySide2.QtWidgets import QWidget # others imports
import cv2

os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.fspath(
    Path(PySide2.__file__).resolve().parent / "Qt" / "plugins"
)

# ...

相关问题