[PyQt] PyQt4 import module fails second time when running python from Qt-C++ based shell

Jack Cosgrove jackcosgrove at gmail.com
Wed May 11 01:14:13 BST 2011


I figured this out. Calling PyFinalize called del() on all loaded
libraries. For some reason this caused QObject to be deleted from QtCore
such that reloading QtCore would not reload QObject. To avoid this I
call PyInitialize and PyFinalize once each at the start and end of the
program.

On Fri, 2011-05-06 at 00:05 -0500, Jack Cosgrove wrote:
> Hi,
> 
> I've attached a small Qt project for a Python shell. It also uses
> QScintilla. It's amazing that I made this in about 5 minutes, thanks
> Phil!
> 
> The problem I'm encountering is that I can only correctly import a PyQt4
> module once using this shell. If I try to import again then I cannot use
> classes within the module. The code
> 
> from PyQt4 import QtCore
> QtCore.QObject()
> 
> succeeds the first time it is run. The second time it complains that
> "AttributeError: 'module' object has no attribute 'QObject'". This does
> not happen with other modules like sys. The Python execution code uses
> all temporary variables.
> 
> At first I thought this was because of a flaw in my C++ code, but the
> success of loading a non-Qt-based modules piqued my curiosity. Has
> anyone ever seen something like this?




More information about the PyQt mailing list