0

I'm trying to create a standalone executable file out of simple qt project.

I do not come across any issues when passing the relative path to 'Ui'.

However if I try to create a standalone executable file out of the project by providing the following command

PyInstaller --onefile --windowed --add-data "C:\***\***\ui;ui" app.py

This command creates an executable file. The resulting program crashes immediately due to the following error

Traceback (most recent call last):
  File "app.py", line 11, in <module>
  File "ui\__init__.py", line 7, in __init__
    self.__ui_file = uic.loadUi(path, self)
  File "PyQt5\uic\__init__.py", line 238, in loadUi
  File "PyQt5\uic\Loader\loader.py", line 66, in loadUi
  File "PyQt5\uic\uiparser.py", line 1020, in parse
  File "xml\etree\ElementTree.py", line 1202, in parse
  File "xml\etree\ElementTree.py", line 584, in parse
FileNotFoundError: [Errno 2] No such file or directory: 'ui\\test.ui'

I do not know the cause of that problem but I expect it to be an issue regarding the relative path. Can anybody help me?

Project structure:

root
+--- ui
     +--- __init__.py 
     +--- test.ui
+--- app.py

Content of /ui/init.py

"""
File: /ui/__init__.py
"""
from PyQt5 import QtWidgets, uic

class Ui(QtWidgets.QMainWindow):

    def __init__(self, path: str) -> None:
        super(Ui, self).__init__()
        self.__ui_file = uic.loadUi(path, self)
        self.show()

    @property
    def it(self): return self.__ui_file

Content of app.py:

"""
File: /app.py
"""
import os
from PyQt5.QtWidgets import QLabel, QPushButton, QApplication
from ui import Ui


def change_label_text(label, text):
    label.setText(text)


app = QApplication([])
window = Ui(os.path.join('ui', 'test.ui'))
headline: QLabel = window.it.headline
button: QPushButton = window.it.button
button.clicked.connect(lambda: change_label_text(headline, 'Hello World!'))
app.exec_()
mr_miyagi
  • 33
  • 2

0 Answers0