<div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">[compiling...]<br><br>./myprog<br>Traceback (most recent call last):<br> File "myprog.py
", line 27, in <module><br> from PyQt4 import QtGui<br>ImportError: cannot import name QtGui</blockquote><div><br>You need to tell the Python interpreter you're building that the PyQt4.QtGui module 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.
<br><br>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):
<br><br>#include <Python.h><br><br>void custom_inittab(void)<br>{<br> /*<br> * Declare the module initialisation function for each module you want<br> * to be a builtin in the custom interpreter. The name of the function
<br> * will be the name of the module with "init" prepended. The modules<br> * must be built as static libraries (using the -k flag to configure.py<br> * for SIP and PyQt).<br> */<br><br> extern void initsip(void);
<br> extern void initQtCore(void);<br> extern void initQtGui(void);<br><br> /*<br> * This structure specifies the names and initialisation functions of<br> * the builtin modules.<br> */<br> struct _inittab builtin_modules[] = {
<br> {"sip", initsip},<br> {"PyQt4.QtCore", initQtCore},<br> {"PyQt4.QtGui", initQtGui},<br> {NULL, NULL}<br> };<br><br> PyImport_ExtendInittab(builtin_modules);
<br>}<br><br></div>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.<br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> As for the inclusion of this patch into the Python official release, the<br>> patch needs to have this problem with the regression test configuration<br>> fixed, and being reviewed. The difficult part is the latter as apparently
<br>> barely anyone reviews Python patches and so the project has a considerable<br>> patch backlog.</blockquote><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">If we got it working it should be a good feature :)</blockquote><div><br>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 difficult.<br></div></div><br>Regards,<br>Miguel<br><br>