Using Py2app with a GUI from QT Creator
Question: I created a GUI in QT Creatro and stored this as a *.ui file. Using PyQT I
made a GUI that works fine when it is launched as

    
    
    $ python pyapp.py
    

In order to build this app into something that can be executed by double
clicking on it, I used Py2app. However, upon clicking the icon twice, I get
the following error in the dialog that appears:

    
    
    pygui Error
    

After opening the console, it seems that the following gives rise to this
error:

    
    
    12/06/2015 15:58:30.084 pygui[29757]: IOError: [Errno 2] No such file or directory: 'mainwindow.ui'
    

It seems that the gui that I created with QT Creator is not found by the app
when it opens. Any idea why this is happening?

Thanks in advance.


Answer: This is happening because py2app would not be able to find files specified
through string paths in the code. It will not include those files in the
binary. You can do one of two things to solve your problem.

1) You have to convert your .ui file to .py file using `pyuic4` (included in
PyQt4 installation). After this step you will have a .py file. Then instead of
using .ui, import .py file and inherit your class from the _class generated in
.py file_. This will allow py2app to include the ui from a python module
instead of searching for .ui file.

2) You can simply manually place the .ui file in the same directory where the
py2app created the binary. It should work without errors.

**UPDATE**

If you want to try 2nd solution, you need to specify the complete path to the
.ui file. You can do this by using `__file__` attribute in the python module.
Instead of `uic.loadUiType("mainwindow.ui")`, use
`uic.loadUiType(os.path.join(os.path.dirname(__file__), "mainwindow.ui"))`

