How to include ui-Files?

3,396 views
Skip to first unread message

snafu

unread,
Mar 29, 2009, 5:29:26 PM3/29/09
to PyInstaller
When doing a layout with the Qt Designer the filetype "ui" is used to
save the content. Is there a way to let a PyInstaller onefile include
those ui-files?

snafu

unread,
Mar 29, 2009, 5:42:58 PM3/29/09
to PyInstaller
And when calling the onefile in a way that makes it available to find
the ui-file, it throws an error, too:

http://paste.pocoo.org/show/110190/

A little example for that:

#!/usr/bin/env python

import sys
from PyQt4 import QtGui, uic


class MainWindow(QtGui.QMainWindow):

def __init__(self, uifile='browser.ui', parent=None):
super(MainWindow, self).__init__(parent)
uic.loadUi(uifile, self)


if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()

Giovanni Bajo

unread,
Mar 29, 2009, 6:21:25 PM3/29/09
to PyIns...@googlegroups.com

Not specifically: .ui files are data files, and PyInstaller is about
packaging your program, not your data.

An easy solution is to use pyuic4 to compile .ui files into Python code.
Otherwise, you may want to read PyInstaller's manual about how to put
arbitrary data files within the generated executable, but it's not
something that it's streamlined to do.
--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


Giovanni Bajo

unread,
Mar 29, 2009, 6:24:39 PM3/29/09
to PyIns...@googlegroups.com
On dom, 2009-03-29 at 14:42 -0700, snafu wrote:
> And when calling the onefile in a way that makes it available to find
> the ui-file, it throws an error, too:
>
> http://paste.pocoo.org/show/110190/
>

This error:

> File "c:\pyinstaller\iu.py", line 446, in importHook
> raise ImportError, "No module named %s" % fqname
> ImportError: No module named QtWebKit

probably happens because the .ui files require the webkit at runtime to
be present, but PyInstaller couldn't know that because it doesn't know
how to parse .ui files, and there probably is not any direct import of
QtWebKit in your code.

To play totally safe, I should probably add a PyQt4.uic import hook that
brings everything in: basically, if you're using PYQt4.uic, it means
that you're loading .ui files and this can bring additional
dependencies. So in doubt I should probably just include the whole PyQt.
Do you agree?

snafu

unread,
Mar 29, 2009, 8:41:25 PM3/29/09
to PyInstaller
Would be nice. I think ui-files are a basic thing in designing Qt
interfaces (same as glade-files in GTK). I think it should be part of
a onefile especially because PyInstaller's goals say that fully Qt
support is aspired. And in my opinion these are not just special data
files...

And you're right: The webkit import is only made in the ui-file. So
some parsing would be necessary. But it would worth the work since ui-
support might be a pleasure for other Qt programmers, too. :-)

snafu

unread,
Mar 29, 2009, 8:47:48 PM3/29/09
to PyInstaller
You actually could call pyuic4 during the build process and use the
resulting py-file which will also include all python calls for the
design.
Reply all
Reply to author
Forward
0 new messages