AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1310286
Accepted
Mona Jalal
Mona Jalal
Asked: 2021-01-23 19:06:26 +0800 CST2021-01-23 19:06:26 +0800 CST 2021-01-23 19:06:26 +0800 CST

qt.qpa.plugin:即使找到了,也无法在“”中加载 Qt 平台插件“xcb”。在 ubuntu 20.04

  • 772

我应该如何在 Ubuntu 20.04 中解决这个问题?

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) 

和

$ echo $DISPLAY
:0

和

$ 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 = <class 'PyQt5.QtGui.QOpenGLVersionProfile'>
QOperatingSystemVersion = <class 'PyQt5.QtCore.QOperatingSystemVersion'>
QT_VERSION = 331522
QT_VERSION_STR = 5.15.2
QVersionNumber = <class 'PyQt5.QtCore.QVersionNumber'>

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

$ 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)

还,

$ 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
>>> 
python
  • 1 1 个回答
  • 15892 Views

1 个回答

  • Voted
  1. Best Answer
    Mona Jalal
    2021-01-27T09:57:48+08:002021-01-27T09:57:48+08:00

    首先这样做:

    $  export DISPLAY=:1.0
    

    我安装的最新版本的 opencv-python 导致了 pyqt5 的问题。所以我卸载了它并安装了以下版本:

    $ pip install opencv-python==4.3.0.36
    

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

    这是我的 pyqt 版本:

    $ 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

相关问题

  • 默认的字符编码是什么?

  • 如何使用 pynotify 创建可点击通知?

  • 有没有安装 Django 1.2.*(最新稳定版)的简单方法?

  • 为 Python 应用程序设置构建系统

  • 为我的 PPA 创建包时遇到问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve