微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PySide6 无法运行

如何解决PySide6 无法运行

我最近安装了 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": {
        "Keys": [
            "linuxfb"
        ]
    },"className": "QLinuxFbIntegrationPlugin","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": {
        "Keys": [
            "minimal"
        ]
    },"className": "QMinimalIntegrationPlugin","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": {
        "Keys": [
            "minimalegl"
        ]
    },"className": "QMinimalEglIntegrationPlugin","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": {
        "Keys": [
            "offscreen"
        ]
    },"className": "QOffscreenIntegrationPlugin","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": {
        "Keys": [
            "vnc"
        ]
    },"className": "QVncIntegrationPlugin","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": {
        "Keys": [
            "wayland-egl"
        ]
    },"className": "QWaylandEglPlatformIntegrationPlugin","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": {
        "Keys": [
            "wayland"
        ]
    },"className": "QWaylandIntegrationPlugin","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": {
        "Keys": [
            "wayland-xcomposite-egl"
        ]
    },"className": "QWaylandxcompositeEglPlatformIntegrationPlugin","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": {
        "Keys": [
            "wayland-xcomposite-glx"
        ]
    },"className": "QWaylandxcompositeGlxPlatformIntegrationPlugin","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": {
        "Keys": [
            "xcb"
        ]
    },"className": "QXcbIntegrationPlugin","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 运行时它仍然不起作用。

EDIT2

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

解决方法

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

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

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

考虑到该文件在我的终端中运行,我知道它必须是我在 VSCode 中做过或没做过的事情。是的,案件已结。

为了专注于我开始参加的这些课程,我已经放下了一段时间,所以并不是说我一直在为此给自己压力。我的解决方案是因为我试图让 matplotlib 显示我试图运行的图形(第一次使用 matplotlib),这就是它的作用。所以我突然想到要为这段代码尝试一下,然后砰的一声,它确实以同样的方式工作。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。