Jun-26-2023, 03:20 PM
Hi All, I'm sure I'm not the first to encounter this but can't seem to find a solution.I hope someone can help.
I'm using W11, python 3.11 & PyQt5. My python code uses the .ui rather than a compiled .py file & I'm trying to use pyinstaller to make a single .exe. Here's an example which shows the problem. I have seen solutions proposed that need the .ui to be compiled into a.py file. I'd rather not go that route if I can help it. It's a pain to have to compile the .ui every time a change is made & I'll also have to re-write my existing code.
.py code:
I'm using pyinstaller --onefile --add-data="helloGUI.ui;." HelloApp.py which seems to work, but when I run the .exe in the dist folder, I get a window pop up with:
Traceback (most recent call last):
File "helloAPP.py", line 20, in <module>
File "helloAPP.py", line 10, in __init__
File "PyQt5\uic\__init__.py", line 241, 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 1218, in parse
File "xml\etree\ElementTree.py", line 569, in parse
FileNotFoundError: [Errno 2] No such file or directory: 'helloGUI.ui'
If I add the .ui file to the dist folder, all is OK. I've also tried running the .exe on a machine without python installed & again all is OK if the .ui is in the same folder.
Thanks in advance, Dave
I'm using W11, python 3.11 & PyQt5. My python code uses the .ui rather than a compiled .py file & I'm trying to use pyinstaller to make a single .exe. Here's an example which shows the problem. I have seen solutions proposed that need the .ui to be compiled into a.py file. I'd rather not go that route if I can help it. It's a pain to have to compile the .ui every time a change is made & I'll also have to re-write my existing code.
.py code:
from PyQt5 import QtWidgets, uic
class HelloApp(object):
def __init__(self, app):
self.app = app
self.ui = uic.loadUi('helloGUI.ui')
self.ui.show()
self.run()
def run(self):
self.app.exec_()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
HelloApp(app)... the .ui xml code from PyQt5<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>132</height>
</rect>
</property>
<property name="windowTitle">
<string>Hello</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<family>Arial</family>
<pointsize>44</pointsize>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>Hello</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>This should just throw up a simple window with Hello in the middle.I'm using pyinstaller --onefile --add-data="helloGUI.ui;." HelloApp.py which seems to work, but when I run the .exe in the dist folder, I get a window pop up with:
Traceback (most recent call last):
File "helloAPP.py", line 20, in <module>
File "helloAPP.py", line 10, in __init__
File "PyQt5\uic\__init__.py", line 241, 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 1218, in parse
File "xml\etree\ElementTree.py", line 569, in parse
FileNotFoundError: [Errno 2] No such file or directory: 'helloGUI.ui'
If I add the .ui file to the dist folder, all is OK. I've also tried running the .exe on a machine without python installed & again all is OK if the .ui is in the same folder.
Thanks in advance, Dave
