繁体   English   中英

PySide6 无法运行

[英]PySide6 failing to run

我最近安装了 PySide 6。我正在运行 Ubuntu 20.04 尝试在 VSCode 上运行我的代码并且刚刚运行:export QT_DEBUG_PLUGINS=1

我收到以下消息:

QFactoryLoader::QFactoryLoader() checking directory path "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqeglfs.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqeglfs.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "eglfs"
        ]
    },
    "archreq": 0,
    "className": "QEglFSIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqlinuxfb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "linuxfb"
        ]
    },
    "archreq": 0,
    "className": "QLinuxFbIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqminimal.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqminimal.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "archreq": 0,
    "className": "QMinimalIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("minimal")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqminimalegl.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqminimalegl.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimalegl"
        ]
    },
    "archreq": 0,
    "className": "QMinimalEglIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqoffscreen.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqoffscreen.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "archreq": 0,
    "className": "QOffscreenIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqvnc.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqvnc.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "vnc"
        ]
    },
    "archreq": 0,
    "className": "QVncIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("vnc")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-egl.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-egl.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "wayland-egl"
        ]
    },
    "archreq": 0,
    "className": "QWaylandEglPlatformIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("wayland-egl")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-generic.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-generic.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "wayland"
        ]
    },
    "archreq": 0,
    "className": "QWaylandIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("wayland")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-xcomposite-egl.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-xcomposite-egl.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "wayland-xcomposite-egl"
        ]
    },
    "archreq": 0,
    "className": "QWaylandXCompositeEglPlatformIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("wayland-xcomposite-egl")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-xcomposite-glx.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqwayland-xcomposite-glx.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "wayland-xcomposite-glx"
        ]
    },
    "archreq": 0,
    "className": "QWaylandXCompositeGlxPlatformIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("wayland-xcomposite-glx")
QFactoryLoader::QFactoryLoader() looking at "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqxcb.so"
Found metadata in lib /home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "archreq": 0,
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 393216
}


Got keys from plugin meta data QList("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/omari/anaconda3/envs/gui_projects/bin/platforms" ...
loaded library "/home/omari/anaconda3/envs/gui_projects/lib/python3.8/site-packages/PySide6/Qt/plugins/platforms/libqxcb.so"
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, xcb.

我已经卸载并重新安装了 PySide 6,但仍然无法让它运行。 我不确定我在该消息中缺少什么,我需要做什么。

我试图运行的代码是:

import sys
import random
from PySide6 import QtCore, QtWidgets, QtGui

class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"]

        self.button = QtWidgets.QPushButton("Click me!")
        self.text = QtWidgets.QLabel("Hello World",
                                     alignment=QtCore.Qt.AlignCenter)

        self.layout = QtWidgets.QVBoxLayout()
        self.layout.addWidget(self.text)
        self.layout.addWidget(self.button)
        self.setLayout(self.layout)

        self.button.clicked.connect(self.magic)

    @QtCore.Slot()
    def magic(self):
        self.text.setText(random.choice(self.hello))

if __name__ == "__main__":
    app = QtWidgets.QApplication([])

    widget = MyWidget()
    widget.resize(800, 600)
    widget.show()

    sys.exit(app.exec_())

这只是“创建一个简单的应用程序”复制并直接从网站粘贴。

关于修复的任何想法? 或者需要更多信息?

我还没有从 qt.io 的论坛或与此问题有关的任何其他文章中遇到任何解决方案。

编辑

到目前为止,我遇到了一项工作。 我可以直接从终端打开文件。 但是,在尝试运行 VSCode 时它仍然无法正常工作。

编辑2

这有可能是 VSCode 扩展问题。 PySide 或 QT 将文件保存在 .ui 中。 我这里的代码是 in.py。 将其更改为 .ui 时,VSCode 提示我使用正确的扩展名来打开它。 我还没有打开它,但我相信这就是我应该如何看待它。 让它在终端中打开,而不是在 VSCode 中打开,告诉我这是 VSCode 所没有的。

所以。!!!! 我终于让它工作了。

在我的工作区 window 中,我所要做的就是右键单击文件,然后在交互式 window 中运行当前文件。 VSCode提示我下载了一个Jupyter notebook kernel,然后就成功了!

或者,使用 Ctrl + Alt + N 运行代码,而不是 Ctrl + F5。 确保已安装 Code Runner 扩展。

考虑到该文件在我的终端中工作,我知道它必须是我在 VSCode 中做过或没有做过的事情。 所以,是的,案件结案。

我已经放下了一段时间来专注于我已经开始学习的这些课程,所以这并不是说我一直在强调自己。 我的解决方案是在我试图让 matplotlib 显示我试图运行的图表时出现的(第一次使用 matplotlib),这就是它的工作原理。 所以我突然想试试这个代码,然后繁荣,它确实以同样的方式工作。

所以,是的,当事情没有按照你想要的方式工作时,不要给自己压力。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM