Mainwindow.ui Error in fbs freeze

Kris | 2020-05-11 10:36:04 UTC | #1

Created a UI using QT Designer, and copied it over to src/main/resources/base/mainwindow.ui

python
Getting this error:
Traceback (most recent call last):
File "main.py", line 15, in <module>
File "PyQt5/uic/ **init** .py", line 199, in loadUiType
File "PyQt5/uic/Compiler/compiler.py", line 111, in compileUi
File "PyQt5/uic/uiparser.py", line 1013, in parse
File "xml/etree/ElementTree.py", line 1197, in parse
File "xml/etree/ElementTree.py", line 587, in parse
FileNotFoundError: [Errno 2] No such file or directory: 'mainwindow.ui'
[61742] Failed to execute script main

Kris | 2020-05-11 10:35:54 UTC | #2

Forgot to mention, fbs run works fine, but fbs freeze causes that traceback.

I load the ui into the app like this:

python
qtCreatorFile = "mainwindow.ui" # UI file here (has to be in same directory).
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

And this is also included at the bottom:

python
if  __name__  == '__main__':
    appctxt = AppContext()
    stylesheet = appctxt.get_resource('mainwindow.ui')
    appctxt.app.setStyleSheet(open(stylesheet).read())
    exit_code = appctxt.run()
    sys.exit(exit_code)

anonymous | 2020-05-11 10:36:49 UTC | #3

Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book

Since fbs is a wrapper around pyinstaller I would assume that pyinstaller is not able to locate that dependency. If using raw pyinstaller then you usually need to specify file & module dependencies if they are not included with an 'import' statement. Not sure about fbs, but this is my experience with pyinstaller


mike2750 | 2020-06-18 15:51:41 UTC | #4

Over 10,000 developers have learnt PyQt using my materials
PyQt6 Crash Course
See the course

5 hours of self-paced video instruction

i think this is due to the relative path issue try this it works for me with fbs and freeze installers and running

python
qtCreatorFile = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "mainwindow.ui")  # Type your file path
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

Also can use the same approach for any other stuff you don't want to use the application context for cached property thing for so when frozen the resources are still work

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!

More info Get the book


Mark As Complete
Martin Fitzpatrick

Mainwindow.ui Error in fbs freeze was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.