"PYSIDE_DESIGNER_PLUGINS"环境变量未设置,退出。"

9
我安装了免费版本的开源qt creator,并创建了一个非常简单的桌面应用程序。我能够创建简单的窗口,但在运行时出现以下错误:
我尝试遵循这个页面,但无法理解如何解决这个问题。

https://www.qt.io/blog/qt-for-python-6.1

Environment variable PYSIDE_DESIGNER_PLUGINS is not set, bailing out.
No instance of QPyDesignerCustomWidgetCollection was found.

Python文件

# This Python file uses the following encoding: utf-8
import os
from pathlib import Path
import sys

from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import QFile
from PySide6.QtUiTools import QUiLoader


    class test(QMainWindow):
        def __init__(self):
            super(test, self).__init__()
            self.load_ui()
    
        def load_ui(self):
            loader = QUiLoader()
            path = os.fspath(Path(__file__).resolve().parent / "form.ui")
            ui_file = QFile(path)
            ui_file.open(QFile.ReadOnly)
            loader.load(ui_file, self)
            ui_file.close()
    
    
    if __name__ == "__main__":
        app = QApplication([])
        widget = test()
        widget.show()
        sys.exit(app.exec_())

添加 xml
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>test3</class>
 <widget class="QMainWindow" name="test3">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1332</width>
    <height>702</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>test3</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QCheckBox" name="checkBox">
    <property name="geometry">
     <rect>
      <x>300</x>
      <y>240</y>
      <width>70</width>
      <height>17</height>
     </rect>
    </property>
    <property name="text">
     <string>CheckBox</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>1332</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFile">
    <property name="title">
     <string>File</string>
    </property>
    <addaction name="actionOpen"/>
    <addaction name="actionsave"/>
   </widget>
   <widget class="QMenu" name="menuEdit">
    <property name="title">
     <string>Edit</string>
    </property>
   </widget>
   <widget class="QMenu" name="menuArchive_and_update_indicator">
    <property name="title">
     <string>Archive and update indicator</string>
    </property>
   </widget>
   <addaction name="menuFile"/>
   <addaction name="menuEdit"/>
   <addaction name="menuArchive_and_update_indicator"/>
  </widget>
  <action name="actionOpen">
   <property name="text">
    <string>Open</string>
   </property>
  </action>
  <action name="actionsave">
   <property name="text">
    <string>Save</string>
   </property>
  </action>
 </widget>
 <resources/>
 <connections/>
</ui>

你能详细解释一下你所采取的步骤来创建那个项目吗?这是一个错误还是一个警告? - eyllanesc
它出现了错误,没有生成输出。 - user765443
分享.py和其他文件。 - eyllanesc
3个回答

8
你正在看到 PySide6 中一个名为“自定义小部件”的新实验性功能的信息提示。要消除该消息,您可以将变量“PYSIDE_DESIGNER_PLUGINS”设置为当前文件夹中的“.”。 https://www.qt.io/blog/qt-for-python-6.1指出:
引入了一个新的实验性插件,适用于 Linux 和 Windows,提供了使用 Python 编写自定义小部件的支持,然后可以从 Qt Designer 中选择并在布局中使用。在 macOS 上需要一些额外的魔法来启用此功能。我们希望在 6.1.1 版本中准备好它!
有关此功能的更多信息,请参见此处:

https://doc-snapshots.qt.io/qtforpython-dev/tutorials/basictutorial/uifiles.html#custom-widgets-in-qt-designer


12
将环境变量设置为“.”并不能使我消除这个信息,它只是将其更改为:“qt.pysideplugin:在'.'中未找到python文件。” 至少现在清楚了这是什么意思,但是否有完全消除它的方法? - S818

1

有一种特别的方法可以使

Environment variable PYSIDE_DESIGNER_PLUGINS is not set, bailing out.

消息消失是设置PYSIDE_DESIGNER_PLUGINS(例如os.environ["PYSIDE_DESIGNER_PLUGINS"]=".")为一个包含空白register*.py文件的文件夹,例如将空文件命名为register_dummy.py

您仍然需要

No instance of QPyDesignerCustomWidgetCollection was found.

因为register_dummy.py文件没有调用QPyDesignerCustomWidgetCollection.registerCustomWidget函数,所以会出现这种情况。要解决这个问题,您只需要创建一个自定义小部件,可以使用链接中提到的wigglywidget,该链接在被接受的答案中提到,也可以在site-packages/PySide6/examples/widgetbinding中找到。


0

暂时禁用警告如何?

os.environ["QT_LOGGING_RULES"]='*.debug=false;qt.pysideplugin=false'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接