【问题标题】:pyqt5: could not connect to displaypyqt5:无法连接到显示器
【发布时间】:2023-03-03 10:29:01
【问题描述】:

我正在学习在 PyQt5 上为 python 构建 GUI。我有一个程序,它使用 opencv 和 pyqt5 在 GUI 上显示带有人脸检测的网络摄像头,并具有启动和停止功能。但是发生了以下错误-

mayank@beware-hoax:~/PythonProjects/gui/pyqt5/pyqt5_face_detection$ source /home/mayank/anaconda3/bin/activate
conda activate gui

(base) mayank@beware-hoax:~/PythonProjects/gui/pyqt5/pyqt5_face_detection$ conda activate gui
/home/mayank/anaconda3/envs/gui/bin/python /home/mayank/PythonProjects/gui/pyqt5/pyqt5_face_detection/main_window.py

(gui) mayank@beware-hoax:~/PythonProjects/gui/pyqt5/pyqt5_face_detection$ /home/mayank/anaconda3/envs/gui/bin/python /home/mayank/PythonProjects/gui/pyqt5/pyqt5_face_detection/main_window.py
qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" 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: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted (core dumped)

【问题讨论】:

  • 记号应该是反引号 --> ``` ,而不是 -->''' 来格式化代码。
  • @MayankLad 执行:export QT_DEBUG_PLUGINS=1 并再次运行您的脚本,在这种情况下您会收到什么消息?
  • @eyllanesc 我发现只有当我使用 Visual Studio 代码运行应用程序时才会出现此错误。当我通过 ubuntu 终端运行时,它运行良好!!

标签: python pyqt pyqt5 python-3.7


【解决方案1】:

这绝对不是最好的解决方案,但我遇到了同样的问题,即无法从代码运行,而且它在终端上运行良好。无论如何,我以 root 权限启动了 vs 代码,我能够克服这个问题并且我的 GUI 启动了。但是,由于安全问题,不建议这样做,这是正确的。

类似这样的东西:How to open Visual Studio Code with admin privileges to make effect of the installed extensions

我认为我的 anaconda 文件夹位置可能与此有关。我希望有人对此提供真正的答案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多