[IPython-user] Using -q4thread IPython option with new style PyQt API?

TP wingusr@gmail....
Sun Feb 21 10:51:46 CST 2010


I'm using Windows XP, IPython 0.10, Python 2.6.4, and PyQt 4.7.1.

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#selecting-incompatible-apis
discusses how to specify the API version to use when dealing with
QVariant, QString, QDate, etc.

The important part of that document is this statement:

    Each API that can be selected in this way has a name and a range
    of version numbers. An application calls sip.setapi() to set the
    version number of a particular API. This call must be made before
    any module that implements the API is imported. Once set the
    version number cannot be changed. If not set then an API will use
    its default version.

Basically I have this at the top of my python file that uses PyQt:

    # This is only needed for Python v2 but is harmless for Python v3.
    import sip
    sip.setapi('QDate', 2)
    sip.setapi('QTime', 2)
    sip.setapi('QDateTime', 2)
    sip.setapi('QUrl', 2)
    sip.setapi('QTextStream', 2)
    sip.setapi('QVariant', 2)
    sip.setapi('QString', 2)

However, when I start IPython by doing:

    python26 ipython.py -q4thread

and then run my program, I get the following error message:

    ValueError Traceback (most recent call last)

    qt4test.pyw in <module>()
	 16 # This is only needed for Python v2 but is harmless for Python v3.
	 17 import sip
    ---> 18 sip.setapi('QDate', 2)
	 19 sip.setapi('QTime', 2)
	 20 sip.setapi('QDateTime', 2)

    ValueError: API 'QDate' has already been set to version 1
    WARNING: Failure executing file: <qt4test.pyw>

I "fixed" the problem by adding the setapi calls mentioned above to
the top of IPython\Shell.py right after the "from signal import
signal, SIGINT" line.


More information about the IPython-user mailing list