[IPython-User] ValueError: API 'QString' has already been set to version 1
Mon Feb 13 15:54:52 CST 2012
On Mon, Feb 13, 2012 at 13:33, Jonathan Stickel <email@example.com> wrote:
> I recently got bit by the error in the subject line. It arose when I
> installed Mayavi-4.1.0 (with pyface-4.1.0 as a dependency) and imported
> mlab. However, it can be reproduced most simply by doing:
> $ ipython --gui=qt
> In : import sip
> In : sip.setapi('QString', 2)
> ValueError Traceback (most recent call last)
> /Users/jstickel/<ipython-input-2-d786b937fa44> in <module>()
> ----> 1 sip.setapi('QString', 2)
> ValueError: API 'QString' has already been set to version 1
Naturally, as `--gui qt` implies an import of PyQt, and any sip.setapi
calls must be done before that happens.
> It also occurs inside a qtconsole started with "ipython qtconsole
True only if the Qt backend is the default. Doesn't affect other matplotlib
backends (using qtconsole *does not* imply qt matplotlib).
> Fortunately, I found that the workaround suggested here:
> $ export QT_API==pyqt
> worked for me. I am using python-2.6. I understand that this will not
> happen with python-3.x. Anyway, I am reporting to this list in case it
> might help others. This might be worth having in the IPython FAQ as well.
This is not a workaround, it is the Right Way to do it, but you are right
in pointing out that it should be better documented.
There was much discussion and consternation about what the default should
be, and we have settled on this:
ETS (and thus mayavi) uses v2, but it is very nearly alone in the Python
world (pre-3.0) in that respect. PyQt's default is v1, and if we forced
v2, we would break compatibility with *many* qt libraries. So the IPython
default is to use PyQt's own defaults. However, if you use the ETS
environment variable to specify the Qt API, then we assume that you are
using ETS, and we should match their choice. Thus you can specify any of
the threeavailable options with this ETS env variable:
QT_API=pyside # use PySide, also affects ETS
QT_API=pyqt # use PyQt v2, matches ETS
QT_API undefined # use PyQt v1, matching library defaults
So the answer is basically: if you use ETS with IPython, you *must* specify
QT_API, because IPython needs to make a decision at import time, and the
logical default is incompatible with ETS.
> IPython-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User