首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >qt.qpa.plugin:即使发现了Qt平台插件"xcb“,也无法加载它。在ubuntu 20.04

qt.qpa.plugin:即使发现了Qt平台插件"xcb“,也无法加载它。在ubuntu 20.04
EN

Ask Ubuntu用户
提问于 2021-01-23 03:06:26
回答 1查看 22.2K关注 0票数 3

如何在Ubuntu20.04中解决这个问题?

代码语言:javascript
运行
复制
Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.xcb: could not connect to display :0
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)
Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.xcb: could not connect to display :0
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)
2224/31772MB(vision) 

代码语言:javascript
运行
复制
$ echo $DISPLAY
:0

代码语言:javascript
运行
复制
$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> from PyQt5 import Qt
>>> vers = ['%s = %s' % (k,v) for k,v in vars(Qt).items() if k.lower().find('version') >= 0 and not inspect.isbuiltin(v)]
>>> print('\n'.join(sorted(vers)))
PYQT_VERSION = 331522
PYQT_VERSION_STR = 5.15.2
QOpenGLVersionProfile = 
QOperatingSystemVersion = 
QT_VERSION = 331522
QT_VERSION_STR = 5.15.2
QVersionNumber = 

作为再现此错误的最小代码,您可以运行以下命令:

代码语言:javascript
运行
复制
$ cat test_qt.py 
'''
====================
3D plots as subplots
====================

Demonstrate including 3D plots as subplots.
'''

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D, get_test_data
from matplotlib import cm
import numpy as np


# set up a figure twice as wide as it is tall
fig = plt.figure(figsize=plt.figaspect(0.5))

#===============
#  First subplot
#===============
# set up the axes for the first plot
ax = fig.add_subplot(1, 2, 1, projection='3d')

# plot a 3D surface like in the example mplot3d/surface3d_demo
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
fig.colorbar(surf, shrink=0.5, aspect=10)

#===============
# Second subplot
#===============
# set up the axes for the second plot
ax = fig.add_subplot(1, 2, 2, projection='3d')

# plot a 3D wireframe like in the example mplot3d/wire3d_demo
X, Y, Z = get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()

$ python test_qt.py 
Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.xcb: could not connect to display :0
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)

另外,

代码语言:javascript
运行
复制
$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import QtCore, QtGui, QtWidgets
>>> 
EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2021-01-26 17:57:48

首先这样做:

代码语言:javascript
运行
复制
$  export DISPLAY=:1.0

我安装的opencv的最新版本导致了pyqt5的问题。因此,我卸载了它并安装了以下版本:

代码语言:javascript
运行
复制
$ pip install opencv-python==4.3.0.36

添加以下信息,以防对未来的读者有所帮助。

这是我的pyqt版本:

代码语言:javascript
运行
复制
$ pip list|grep Qt
PyQt5                  5.15.2
PyQt5-sip              12.8.1


$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux

$ pip --version
pip 21.0 from /home/mona/venv/vision/lib/python3.8/site-packages/pip (python 3.8)

$ lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal

学分:https://stackoverflow.com/a/63350799/2414957

票数 9
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1310286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档