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
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:
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:
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.
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
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