Mainwindow.ui Error in fbs freeze

Heads up! You've already completed this tutorial.

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

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

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


The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

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.