简体   繁体   English

PySide6 无法运行

[英]PySide6 failing to run

I've recently installed PySide 6. I'm running Ubuntu 20.04 Attempting to run my code on VSCode And have just ran: export QT_DEBUG_PLUGINS=1我最近安装了 PySide 6。我正在运行 Ubuntu 20.04 尝试在 VSCode 上运行我的代码并且刚刚运行:export QT_DEBUG_PLUGINS=1

I'm getting the following message:我收到以下消息:

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.

I've uninstalled and reinstalled PySide 6 and am still unable to get it to run.我已经卸载并重新安装了 PySide 6,但仍然无法让它运行。 I'm not sure what I'm missing in that message as to what I need to do.我不确定我在该消息中缺少什么,我需要做什么。

The code I'm trying to run is:我试图运行的代码是:

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_())

Which is only the "Create a simple application" copy and pasted directly from the website.这只是“创建一个简单的应用程序”复制并直接从网站粘贴。

Any ideas on a fix?关于修复的任何想法? Or more information needed?或者需要更多信息?

I have yet to come across any solutions from qt.io's forums, or any other articles pertaining to this issue.我还没有从 qt.io 的论坛或与此问题有关的任何其他文章中遇到任何解决方案。

EDIT编辑

So far I've come across one work around.到目前为止,我遇到了一项工作。 I can open the file directly from the terminal.我可以直接从终端打开文件。 It still isn't working when trying to run through VSCode though.但是,在尝试运行 VSCode 时它仍然无法正常工作。

EDIT2编辑2

There's a chance this can be a VSCode Extension issue.这有可能是 VSCode 扩展问题。 PySide, or QT for that matter, saves files in.ui. PySide 或 QT 将文件保存在 .ui 中。 My code here is in.py.我这里的代码是 in.py。 When changing it to.ui VSCode was prompting me for the proper extension to open it with.将其更改为 .ui 时,VSCode 提示我使用正确的扩展名来打开它。 I haven't opened it yet, but I believe that to be how I should be looking at this.我还没有打开它,但我相信这就是我应该如何看待它。 For it to open in the terminal, but not VSCode, tells me that it's something VSCode doesn't have.让它在终端中打开,而不是在 VSCode 中打开,告诉我这是 VSCode 所没有的。

So.!!!!所以。!!!! I've FINALLY gotten it to work.我终于让它工作了。

In my workspace window, all I had to do was right click the file, and run current file in interactive window.在我的工作区 window 中,我所要做的就是右键单击文件,然后在交互式 window 中运行当前文件。 VSCode prompted that I download a Jupyter notebook kernel, and then it worked! VSCode提示我下载了一个Jupyter notebook kernel,然后就成功了!

Alternately, run your code with Ctrl + Alt + N, as opposed to Ctrl + F5.或者,使用 Ctrl + Alt + N 运行代码,而不是 Ctrl + F5。 Make sure you have the Code Runner extension installed.确保已安装 Code Runner 扩展。

Considering the file worked in my terminal, I knew it had to be something I was or wasn't doing in VSCode.考虑到该文件在我的终端中工作,我知道它必须是我在 VSCode 中做过或没有做过的事情。 So yeah, case closed.所以,是的,案件结案。

I had put it down for a while to focus on these courses I've started taking, so it wasn't that I was stressing myself out with this the whole time.我已经放下了一段时间来专注于我已经开始学习的这些课程,所以这并不是说我一直在强调自己。 My solution came about as I was trying to get matplotlib to show a graph that I was trying to get to run (first time using matplotlib), and that's what worked for that.我的解决方案是在我试图让 matplotlib 显示我试图运行的图表时出现的(第一次使用 matplotlib),这就是它的工作原理。 So it dawned on me to try it for this code, then boom, it indeed worked the same way.所以我突然想试试这个代码,然后繁荣,它确实以同样的方式工作。

So yeah, don't stress yourself out when something isn't working the way you want it to.所以,是的,当事情没有按照你想要的方式工作时,不要给自己压力。

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

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