[PyQt] Cx_freeze

Miguel Lobo mlobol at gmail.com
Mon Jun 11 19:52:14 BST 2007

> [compiling...]
> ./myprog
> Traceback (most recent call last):
>   File "myprog.py", line 27, in <module>
>     from PyQt4 import QtGui
> ImportError: cannot import name QtGui

You need to tell the Python interpreter you're building that the
PyQt4.QtGuimodule is built-in so it does not look for it in the
filesystem.  To do that
you need to call PyImport_ExtendInittab (which is part of the Python C API)
with the appropriate parameters before the interpreter starts.

You can achieve that by modifying the main function of the frozen program,
which is in the frozen.c file that freeze.py generates.  From the main
function, you can call a function like this (derived from custom/custom.c
from the sip source distribution):

#include <Python.h>

void custom_inittab(void)
     * Declare the module initialisation function for each module you want
     * to be a builtin in the custom interpreter.  The name of the function
     * will be the name of the module with "init" prepended.  The modules
     * must be built as static libraries (using the -k flag to configure.py
     * for SIP and PyQt).

    extern void initsip(void);
    extern void initQtCore(void);
    extern void initQtGui(void);

     * This structure specifies the names and initialisation functions of
     * the builtin modules.
    struct _inittab builtin_modules[] = {
        {"sip", initsip},
        {"PyQt4.QtCore", initQtCore},
        {"PyQt4.QtGui", initQtGui},
        {NULL, NULL}


By the way, don't forget you need to link your program with the static sip
and PyQt libraries; otherwise the linker will complain that the init*
symbols above are unresolved.

> As for the inclusion of this patch into the Python official release, the
> > patch needs to have this problem with the regression test configuration
> > fixed, and being reviewed.  The difficult part is the latter as
> apparently
> > barely anyone reviews Python patches and so the project has a
> considerable
> > patch backlog.

> If we got it working it should be a good feature :)

I agree, but at the moment I don't have access to a good Linux development
machine so I haven't tried to fix Setup.dist.  If you are comfortable with
bash scripts you could give it a try yourself -- I think it shouldn't be too

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070611/0bfca464/attachment-0001.html

More information about the PyQt mailing list