[PyKDE] Re: embedding python widgets in C++ app

Patrick Stinson patrickkidd.lists at gmail.com
Sat Jan 27 04:21:47 GMT 2007


ok, removing all instances of "PyQt4." from the cpp, and without
modifying the sip files, I get this error for
PyRun_SimpleString("import QtCore; print QtCore"):

SystemError: _PyImport_FixupExtension: module QtCore not loaded

and this error for PyRun_SimpleString("import QtGui; print QtGui"):

ImportError: No module named PyQt4.QtCore

After changing the module names in the sip files and recompiling the
PyQt4 static libs it seems to work. I That means that the PyQt4
package definately gets in the way.

So this looks fine except everyone on our team has to do this
everytime they download a new version. Ideas?

On 1/26/07, Patrick Stinson <patrickkidd.lists at gmail.com> wrote:
> then wouldn't the modulename in the sip file have to not be PyQt4.QtCore?
>
> I'll give it a shot in my cpp, then I'll try changing the module name
> in the sip file and rebuilding pyqt...
>
> On 1/26/07, Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > On Friday 26 January 2007 11:03 pm, you wrote:
> > > ok, so I added them back in but have the following problem:
> > >
> > >       struct _inittab builtin_modules[] = {
> > >         { "sip", initsip },
> > >         { "PyQt4.QtCore", initQtCore },
> > >         { "PyQt4.QtGui", initQtGui },
> > >         { NULL, NULL }
> > >       };
> > >
> > >       PyImport_ExtendInittab(builtin_modules);
> > >
> > >       printf("Initializing Python...");
> > >       Py_Initialize();
> > >       printf(" done.\n");
> > >       printf("\n");
> > >
> > >       PyRun_SimpleString("import sys; print sys.builtin_module_names");
> > >       PyRun_SimpleString("import PyQt4.QtGui; print PyQt4.QtGui");
> > >       printf("\n");
> > >
> > >       PyRun_SimpleString("import sys; print sys.builtin_module_names");
> > >
> > >       PyRun_SimpleString("import sys; print
> > > sys.modules['__builtin__'].__dict__['PyQt4.QtCore']");
> > >       printf("\n");
> > >
> > >       PyRun_SimpleString("from PyQt4.QtGui import QWidget\n"
> > >                          "class Widget(QWidget): \n"
> > >                          "    pass");
> > >
> > >
> > >
> > > ...yields...
> > >
> > >
> > >
> > > Initializing Python... done.
> > >
> > > ('PyQt4.QtCore', 'PyQt4.QtGui', '__builtin__', '__main__', '_codecs',
> > > '_sre', '_symtable', 'errno', 'exceptions', 'gc', 'imp', 'marshal',
> > > 'posix', 'signal', 'sip', 'sys', 'thread', 'xxsubtype', 'zipimport')
> > > Traceback (most recent call last):
> > >   File "<string>", line 1, in ?
> > > ImportError: No module named PyQt4.QtGui
> > >
> > > ('PyQt4.QtCore', 'PyQt4.QtGui', '__builtin__', '__main__', '_codecs',
> > > '_sre', '_symtable', 'errno', 'exceptions', 'gc', 'imp', 'marshal',
> > > 'posix', 'signal', 'sip', 'sys', 'thread', 'xxsubtype', 'zipimport')
> > > Traceback (most recent call last):
> > >   File "<string>", line 1, in ?
> > > KeyError: 'PyQt4.QtCore'
> > >
> > > Traceback (most recent call last):
> > >   File "<string>", line 1, in ?
> > > ImportError: No module named PyQt4.QtGui
> > > turin:~/test patrick$
> >
> > The other obvious thing to try is to ignore the PyQt4 package completely. In
> > the inittab put...
> >
> >     {"QtCore", initQtCore}
> >
> > ...and then...
> >
> >     PyRun_SimpleString("import QtCore; print QtCore");
> >
> > Phil
> >
>
>
> --
> Patrick Kidd Stinson
> http://www.patrickkidd.com/
> http://pkaudio.sourceforge.net/
> http://pksampler.sourceforge.net/
>


-- 
Patrick Kidd Stinson
http://www.patrickkidd.com/
http://pkaudio.sourceforge.net/
http://pksampler.sourceforge.net/




More information about the PyQt mailing list