首页 > 解决方案 > pyqt5:无法连接到显示器

问题描述

我正在学习在 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)

标签: pythonpyqtpyqt5python-3.7

解决方案


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

像这样:如何以管理员权限打开 Visual Studio Code 以使已安装的扩展生效

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


推荐阅读