Sypder and enthought.traits.ui

166 views
Skip to first unread message

pblelloch

unread,
Aug 14, 2011, 11:14:11 AM8/14/11
to spyder
I've found that I can't use the enthought.traits.ui package from
within spyder. When I import it I get the following error:

Warning/PyQt4-Spyder (API 'QString' has already been set to version 1)

I then get very strange behavior when creating plots using
matplotlib. Either the figure just comes up and then just hangs, or
it appears momentarily and then disappears. If I do the same thing
outside of Spyder it seems to run fine.

I really like working in the Spyder environment if possible. Does
anyone know how to correct this?

Pierre Raybaut

unread,
Aug 15, 2011, 4:33:26 AM8/15/11
to spyd...@googlegroups.com
Hi,

This behavior is due to the fact that the Enthought Tool Suite is
(trying) to use PyQt API #2 but, before that, Spyder's machinery has
already imported PyQt with the default API (which is API #1 with
Python 2.x).

To avoid this behavior, you just have to prevent Spyder from importing
PyQt. Depending on the Spyder's version that you are using, it means
that you have to disable the "Remove PyQt Input Hook" option and the
"Matplotlib patch" option - and eventually the "Monitor" features (all
these options are available from the preferences panel).

HTH,
Pierre

> --
> You received this message because you are subscribed to the Google Groups "spyder" group.
> To post to this group, send email to spyd...@googlegroups.com.
> To unsubscribe from this group, send email to spyderlib+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spyderlib?hl=en.
>

pblelloch

unread,
Aug 15, 2011, 10:02:04 AM8/15/11
to spyder
Thanks,

Turning off the "Remove PyQt input hook" seemed to fix the problem. I
also found the "Patch Matplotlib figures," but that unchecking that
did not seem to be immediately necessary. Both of those were on the
Console/External modules form. I did not find the "Monitor" features.
I'm curious as to capability I lose by disabling these options. Would
it be better to change the default backend for either Matplotlib or
ETS?

On Aug 15, 1:33 am, Pierre Raybaut <pierre.rayb...@gmail.com> wrote:
> Hi,
>
> This behavior is due to the fact that the Enthought Tool Suite is
> (trying) to use PyQt API #2 but, before that, Spyder's machinery has
> already imported PyQt with the default API (which is API #1 with
> Python 2.x).
>
> To avoid this behavior, you just have to prevent Spyder from importing
> PyQt. Depending on the Spyder's version that you are using, it means
> that you have to disable the "Remove PyQt Input Hook" option and the
> "Matplotlib patch" option - and eventually the "Monitor" features (all
> these options are available from the preferences panel).
>
> HTH,
> Pierre
>

Pierre Raybaut

unread,
Aug 15, 2011, 12:10:02 PM8/15/11
to spyd...@googlegroups.com
Le 15 août 2011 à 16:02, pblelloch <paul.b...@gmail.com> a écrit :

> Thanks,
>
> Turning off the "Remove PyQt input hook" seemed to fix the problem. I
> also found the "Patch Matplotlib figures," but that unchecking that
> did not seem to be immediately necessary. Both of those were on the
> Console/External modules form. I did not find the "Monitor" features.

Monitor settings are in the 'Introspection/...' tab of Console preferences.

> I'm curious as to capability I lose by disabling these options. Would
> it be better to change the default backend for either Matplotlib or
> ETS?

Actually there is no other solution as ETS only supports PyQt API #2.
But if you don't have to disable the Monitor features, that's really
not a problem: the other two options are not so important.

-Pierre

pblelloch

unread,
Aug 15, 2011, 12:14:24 PM8/15/11
to spyder
Thank you. I'll keep all three settings in mind.

On Aug 15, 9:10 am, Pierre Raybaut <pierre.rayb...@gmail.com> wrote:

pblelloch

unread,
Aug 16, 2011, 11:45:14 AM8/16/11
to spyder
I thought that this was working, but now it's not. I have all three
options ("Remove PyQtinput hook", "Patch Matplotlib figures", and
"Enable Monitor")d isabled in the preferences, but I still get the
following error when I import enthought.traits.ui.api:

In [2]: from enthought.traits.ui.api import *
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\api.py", line 35, in <module>
from .editors.api import (ArrayEditor, BooleanEditor,
ButtonEditor,
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\editors\__init__.py", line 22, in <module>
from .api import (toolkit, ArrayEditor, BooleanEditor,
ButtonEditor,
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\editors\api.py", line 10, in <module>
from .code_editor import CodeEditor
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\editors\code_editor.py", line 36, in <module>
class ToolkitEditorFactory ( EditorFactory ):
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\editors\code_editor.py", line 48, in
ToolkitEditorFactory
mark_color = Color( 0xECE9D8 )
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\traits.py", line 486, in __call__
return self.maker_function( *args, **metadata )
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\traits.py", line 1182, in Color
return ColorTrait( *args, **metadata )
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\toolkit_traits.py", line 7, in ColorTrait
return toolkit().color_trait( *args, **traits )
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\toolkit.py", line 109, in toolkit
_toolkit = _import_toolkit(ETSConfig.toolkit)
File "C:\Python26\lib\site-packages\traits-3.6.0-py2.6-win32.egg
\enthought\traits\ui\toolkit.py", line 51, in _import_toolkit
return __import__( name, globals=globals(), level=1 ).toolkit
File "C:\Python26\lib\site-packages\traitsbackendqt-3.6.0-py2.6.egg
\enthought\traits\ui\qt4\__init__.py", line 18, in <module>
import enthought.qt
File "C:\Python26\lib\site-packages\enthoughtbase-3.1.0-py2.6.egg
\enthought\qt\__init__.py", line 22, in <module>
sip.setapi('QString', 2)
ValueError: API 'QString' has already been set to version 1

Am I missing something else?

-Paul

moon

unread,
Aug 23, 2011, 4:14:34 AM8/23/11
to spyder
I have the same problem while importing mayavi from the enthought
toolbox.

I have tried all combinations of options
"Remove PyQt input hook",
"ignore API change errors (sip.setapi)"
"patch matplotlib figures"
"enable monitor"
and furthermore I tried some changes in the IPython interpreter
options.

I am using Spyder 2.0.12 in combination with ETS 3.6.0

Pierre Raybaut

unread,
Aug 30, 2011, 11:38:59 AM8/30/11
to spyd...@googlegroups.com
Hi,

I have implemented a new option in Console preferences to select PyQt
API version number at runtime. This should avoid those issues - at
least I've tested this with almost the same configuration as yours.

It requires the latest development version of Spyder.

HTH
Pierre

Reply all
Reply to author
Forward
0 new messages