[PyKDE] Using SIP modules from embedded Python

Phil Thompson phil at riverbankcomputing.co.uk
Mon Feb 19 15:34:40 GMT 2007


On Monday 19 February 2007 3:15 pm, Paul Giannaros wrote:
> On Monday 19 February 2007 13:34, Phil Thompson wrote:
> > On Monday 19 February 2007 12:55 pm, Paul Giannaros wrote:
> > > Hi there,
> > > I have wrapped key bits of Kate's interface (as documented at
> > > http://developer.kde.org/documentation/library/3.5-api/kdebase-apidocs/
> > >ka te /html/) with SIP. Firstly, thanks for SIP -- along with good
> > > documentation, ease of use, and Qt/KDE support it was a piece of cake.
> > > However, my intention is to use that library from within a C++ Kate
> > > Plugin. The plugin embeds Python and (so far) just attempts to import
> > > the SIP-created module. Doing so gives an ImportError, however, which I
> > > do not get if I just import the module from the interactive
> > > interpreter.
> > >
> > > The error is:
> > > ImportError: /usr/lib/python2.5/site-packages/sip.so: undefined symbol:
> > > _Py_ZeroStruct.
> > >
> > > Both my C++ plugin and my SIP extension link to python (the SIP
> > > extension does because if I don't I get a 'PyCObject_Type' undefined
> > > error when trying to import it).
> > >
> > > Another interesting thing is that If I isolate the importing code from
> > > the Kate plugin with a simple application, it imports fine.
> > >
> > > Any ideas what's going wrong?
> >
> > There are a couple of things your plugin needs to do (for a Qt4 example
> > see the new Designer plugin in current PyQt4 snaphots).
> >
> > You need to make sure the Python shared library is loaded and that it
> > exports all of its symbols.
>
> I'm currently just linking to it on the command line (via -lpython2.5) when
> I link my library. I see from designer/pluginloader.cpp that you use
> QLibrary::load as well? I tried doing that but setLoadHints isn't available
> here (Qt 3.3) and just calling load() causes the same error.

There is a way to do it - but I can't remember what it is at the moment. Have 
a look through the PyKDE source code - it will be in there somewhere - 
related to loading KParts.

> > You should also make sure you link against the Python shared library and
> > not the static one.
>
> I can verify that I'm linking to the shared library via `ldd
> mykateplugin.so`: ....
> libpython2.5.so.1.0 => /usr/lib/libpython2.5.so.1.0 (0xb7d16000
> ....

Phil




More information about the PyQt mailing list