[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Errors with Python Subinterpreters
From:       Gerard Vermeulen <gvermeul () grenoble ! cnrs ! fr>
Date:       2002-10-25 7:33:05
[Download RAW message or body]

On Fri, Oct 25, 2002 at 12:28:27AM +0200, Franz wrote:
> Hello,
> 
> my name is Franz Schmid and I'm the developer ot Scribus, a
> DTP-Package for Linux based on the QT3 GUI.
> 
> To extend the possibiltys of my Program I've included an embedded
> Python Interpreter. This works pretty well.
> 
> Since Scribus uses QT, it seems that it's recommended to use PyQt
> for creating some script driven Dialogs.
> 
> But... When I run a PyQt-Script the very first time it works perfectly,
> trying it to run a second time or running another script that contains
> import qt or from qt import * it fails with the following error message:
> 
> Traceback (most recent call last):
>   File "<string>", line 4, in ?
>   File "/home/franz/PyQtTest.py", line 9, in ?
>     from qt import *
>   File "/usr/local/lib/python2.1/site-packages/qt.py", line 925, in ?
>     libqtc.sipRegisterClasses()
> RuntimeError: SIP - module "qt" implements QObject but it has already been implemented
> 
> Scribus uses Py_NewInterpreter()  to create a new Python Interpreter
> for every Script that should be run, to ensure that every Script has a
> clean namespace.
> 
I would try to solve this by catching the RuntimeError like this:

try:
    from qt import *
except RuntimeError:
    pass

Another possibility is to check if qt has been imported by trying
to use one of its functions:

>>> try:
...     qVersion()
... except NameError:
...     from qt import *
...
>>>

It is not garanteed to work, though :-)
Hope, you are lucky.

Gerard

_______________________________________________
PyKDE mailing list    PyKDE@mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic