Python Forum
Using pyinstaller with .ui GUI files - No such file or directory error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using pyinstaller with .ui GUI files - No such file or directory error
#1
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:
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
Reply


Messages In This Thread
Using pyinstaller with .ui GUI files - No such file or directory error - by diver999 - Jun-26-2023, 03:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Filer and sort files by modification time in a directory tester_V 5 452 May-02-2024, 05:39 PM
Last Post: tester_V
  Loop through all files in a directory? Winfried 10 738 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 559 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  change directory of save of python files akbarza 3 1,049 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Coding error. Can't open directory EddieG 6 1,222 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Monitoring a Directory for new mkv and mp4 Files lastyle 3 1,768 May-07-2023, 12:33 PM
Last Post: deanhystad
Photo exe created by pyinstaller only works in the dist directory dee 7 2,973 Feb-23-2023, 05:53 PM
Last Post: dee
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 1,105 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,204 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 1,676 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020