[PyQt] Linking Qt statically into a project using embedded Python and Sip/PyQt

Ulrich Berning ulrich.berning at denviso.de
Wed Feb 4 15:42:30 GMT 2009

George Goussard wrote:

> Hello.
> My project that I am currently working on is a cross-platform C++ 
> project. On Linux 32-bit/64-bit I have the constraint that I MUST link 
> Qt (4.3.3) in statically with the project. This is a given and cannot 
> be compromised. I have successfully embedded Python into our 
> application and with this facility I can run external Python *.py 
> files. With the help of Sip/PyQt used in these *.py files I can route 
> the output to a nice window inside my Qt application etc. etc. 
> But,....the problem is that it only works if I link Qt in dynamically 
> to my application.
> The reason(I think – when I link dynamically to Qt) is because my 
> application loads the Qt *.so file dynamically when I startup the 
> application. Then when the application runs an external *.py file and 
> it has the line “from PyQt import QtCore” then I suppose that it sees 
> the *.so is already loaded and uses it. Now my question: How can I 
> either get the Python mechanism or Sip/PyQt to rather use the 
> statically linked in Qt with my project?
> Currently, if I link Qt statically into my application and run the 
> *.py files I get some strange Qt message on the command line and then 
> it crashes.
> George.
The only way to do this, is to have everything statically linked:
- Build a static Python library
- Build a static SIP library
- Build static PyQt libraries

Use PyImport_ExtendInittab() to declare the module initialization 
functions for SIP and all PyQt modules you need in your application. 
This must be done before you initialize the python interpreter with 


More information about the PyQt mailing list