Repository navigation
Description
I am trying to use Mayavi in IPython (terminal at the moment) and am running into issues that are surprising me in light of the documentation on this issue.
Specifically, following this page: http://ipython.readthedocs.io/en/stable/interactive/reference.html#pyqt-and-pyside
I have done
[mlw-mbair ~]$ QT_API=pyqt ipython --gui qtbut importing mayavi fails:
In [1]: from mayavi import mlab---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-3f0e4b94a8ea> in <module>()
----> 1 from mayavi import mlab
/Users/mwaskom/anaconda/lib/python2.7/site-packages/mayavi/mlab.py in <module>()
25
26 # Mayavi imports
---> 27 from mayavi.tools.camera import view, roll, yaw, pitch, move
28 from mayavi.tools.figure import figure, clf, gcf, savefig, \
29 draw, sync_camera, close, screenshot
/Users/mwaskom/anaconda/lib/python2.7/site-packages/mayavi/tools/camera.py in <module>()
23 # We can't use gcf, as it creates a circular import in camera management
24 # routines.
---> 25 from .engine_manager import get_engine
26
27
/Users/mwaskom/anaconda/lib/python2.7/site-packages/mayavi/tools/engine_manager.py in <module>()
10
11 # Local imports
---> 12 from mayavi.preferences.api import preference_manager
13 from mayavi.core.registry import registry
14 from mayavi.core.engine import Engine
/Users/mwaskom/anaconda/lib/python2.7/site-packages/mayavi/preferences/api.py in <module>()
2
3 # The global PreferenceManager instance
----> 4 from .preference_manager import preference_manager
5 from .bindings import set_scene_preferences, get_scene_preferences
/Users/mwaskom/anaconda/lib/python2.7/site-packages/mayavi/preferences/preference_manager.py in <module>()
27 from traits.etsconfig.api import ETSConfig
28 from traits.api import HasTraits, Instance
---> 29 from traitsui.api import View, Group, Item
30 from apptools.preferences.api import (ScopedPreferences, IPreferences,
31 PreferencesHelper)
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/api.py in <module>()
34
35 try:
---> 36 from .editors.api import ArrayEditor
37 except ImportError:
38 # ArrayEditor depends on numpy, so ignore if numpy is not present.
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/editors/__init__.py in <module>()
21
22 try:
---> 23 from .api import ArrayEditor
24 except ImportError:
25 pass
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/editors/api.py in <module>()
22 from .button_editor import ButtonEditor
23 from .check_list_editor import CheckListEditor
---> 24 from .code_editor import CodeEditor
25 from .color_editor import ColorEditor
26 from .compound_editor import CompoundEditor
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/editors/code_editor.py in <module>()
34 #-------------------------------------------------------------------------------
35
---> 36 class ToolkitEditorFactory ( EditorFactory ):
37 """ Editor factory for code editors.
38 """
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/editors/code_editor.py in ToolkitEditorFactory()
46
47 # Background color for marking lines
---> 48 mark_color = Color( 0xECE9D8 )
49
50 # Object trait containing the currently selected line (optional)
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traits/traits.pyc in __call__(self, *args, **metadata)
520
521 def __call__ ( self, *args, **metadata ):
--> 522 return self.maker_function( *args, **metadata )
523
524 class TraitImportError ( TraitFactory ):
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traits/traits.pyc in Color(*args, **metadata)
1234 from traitsui.toolkit_traits import ColorTrait
1235
-> 1236 return ColorTrait( *args, **metadata )
1237
1238 Color = TraitFactory( Color )
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/toolkit_traits.pyc in ColorTrait(*args, **traits)
5
6 def ColorTrait ( *args, **traits ):
----> 7 return toolkit().color_trait( *args, **traits )
8
9 def RGBColorTrait ( *args, **traits ):
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/toolkit.pyc in toolkit(*toolkits)
159 try:
160 with provisional_toolkit(toolkit_name):
--> 161 _toolkit = _import_toolkit(toolkit_name)
162 return _toolkit
163 except (AttributeError, ImportError) as exc:
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/toolkit.pyc in _import_toolkit(name)
81
82 def _import_toolkit ( name ):
---> 83 return __import__( name, globals=globals(), level=1 ).toolkit
84
85
/Users/mwaskom/anaconda/lib/python2.7/site-packages/traitsui/qt4/__init__.py in <module>()
16 # import pyface.qt before anything else is done so the sipapi
17 # can be set correctly if needed
---> 18 import pyface.qt
19
20 #----------------------------------------------------------------------------
/Users/mwaskom/anaconda/lib/python2.7/site-packages/pyface/qt/__init__.py in <module>()
38
39 elif qt_api == 'pyqt':
---> 40 prepare_pyqt4()
41
42 elif qt_api != 'pyside':
/Users/mwaskom/anaconda/lib/python2.7/site-packages/pyface/qt/__init__.py in prepare_pyqt4()
15 # Set PySide compatible APIs.
16 import sip
---> 17 sip.setapi('QDate', 2)
18 sip.setapi('QDateTime', 2)
19 sip.setapi('QString', 2)
ValueError: API 'QDate' has already been set to version 1Based on the docs I thought QT_API would use PyQT API v2 and thus be compatible with mayavi.
I am not, to my knowledge, importing anything else that would be setting the QT API ahead of time; i.e. my ipython startup file is pretty clean:
[mlw-mbair ~]$ grep '^\w' ~/.ipython/profile_default/ipython_config.py
c = get_config()
c.TerminalIPythonApp.display_banner = False
c.TerminalIPythonApp.display_banner = False
c.TerminalInteractiveShell.separate_in = ''
c.TerminalInteractiveShell.colors = 'Linux'I am using an up-to-date version of IPython:
[mlw-mbair ~]$ python -c "import IPython; print(IPython.sys_info())"
{'commit_hash': u'5a894b9',
'commit_source': 'installation',
'default_encoding': 'UTF-8',
'ipython_path': '/Users/mwaskom/anaconda/lib/python2.7/site-packages/IPython',
'ipython_version': '5.3.0',
'os_name': 'posix',
'platform': 'Darwin-13.4.0-x86_64-i386-64bit',
'sys_executable': '/Users/mwaskom/anaconda/bin/python',
'sys_platform': 'darwin',
'sys_version': '2.7.12 |Anaconda 2.3.0 (x86_64)| (default, Jul 2 2016, 17:43:17) \n[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)]'}
and (as I think this might be relevant) matplotlib:
[mlw-mbair ~]$ python -c "import matplotlib; print(matplotlib.__version__)"
2.0.0
This used to work for me in the past, but various things have been updated since. I'm not sure if something has broken, or that section of the docs have gone stale, or I'm simply doing something wrong.
Activity
mwaskom commentedon Mar 8, 2017
Also maybe relevant(?): activating the QT gui backend after importing mayavi works fine:
ccordoba12 commentedon Mar 8, 2017
I think the problem is IPython sets the PyQt API to
#1for some APIs but not others. @patricksnape tried to fix this odd behavior but (I think) his PR was declined.mwaskom commentedon Mar 8, 2017
This PR I think you mean: #10101
mwaskom commentedon Mar 8, 2017
However, unless I am misreading the docs, this shouldn't be the issue because
QT_API=pyqtshould set things to V2, as stated here:mwaskom commentedon Mar 8, 2017
It does seem like the IPython gui machinery is setting the QDate API:
ccordoba12 commentedon Mar 9, 2017
So the problem is that
%gui qtsets Sip API to#1and that can't be changed to#2, which is whatpyfaceis trying to do.In Spyder we adopted API
#2because#1was used in PyQt 4.6 and older versions (and that's like 5 years old now). So far we haven't received complaints about it.mwaskom commentedon Mar 9, 2017
Then I'm correct at least that the IPython QT documentation is incorrect?
patricksnape commentedon Mar 11, 2017
This is exactly the problem I was having and trying to fix in my PR
mwaskom commentedon Mar 11, 2017
In light of my experience with this issue, I feel a little confused about why @patricksnape's PR (https://github.com/ipython/ipython/pull/10101/files) was rejected. @takluyver's position seems to be that IPython should leave un-set QT API components that it is not using. That make sense! However, that does not seem to be to existing behavior.
%gui qtis setting QT API components to version 1, even when it shouldn't be (due to usage of theQT_APIenvironment variable as specified in the docs).My issue isn't about dealing with headaches from mixing applications that want different QT APIs; it's simply about not being able to use a single application (mayavi) that wants version 2.
Carreau commentedon Mar 13, 2017
If this happen to be really problematic, and qt-users agree in majority that v2 should be set on all apis at once, then I think we can revisit #10101.
had anyone had a look at https://pypi.python.org/pypi/Qt.py ?
ccordoba12 commentedon Mar 13, 2017
I'm +1 for that move. As I said, v1 is quite old and most probably very few projects are using it at the moment.
That package is a shim for Pyside/PyQt4/PyQt5, and there's another one called qtpy developed by us for Spyder.
If there's a decision to adopt a Qt shim, I'd vote for
qtpybecause it's part of the community (Glue is also using it).Carreau commentedon Mar 14, 2017
I thinks there was a consensus at today's meeting to reopen #10101 which is now done.
we'll try to get this in soon.
takluyver commentedon Mar 14, 2017
The issue is that there are a bunch of separate APIs with different versions, each of which you need to pick one of, but as soon as PyQt is imported, they're all fixed. We're not explicitly setting QDate v1, but because we import PyQt to set up the event loop integration, we're implicitly setting the default PyQt gives us.
I still suspect that we're likely to run into more issues if we suddenly start setting the QDate API to v2. Remember that anyone for whom it would break is not looking at this issue, so the +1s we see here are not a remotely representative sample.
mwaskom commentedon Mar 14, 2017
That's fine but even if nothing changes in the code, I still think the docs are incorrect :)
And FWIW, I am almost certain that my usecase worked fine until pretty recently. Not sure exactly what update broke it, though.
6 remaining items
mwaskom commentedon Apr 24, 2017
Just came across a somewhat older application of mine that used to work but now doesn't because of this issue: https://github.com/mwaskom/connexplore
It's not super useful for pinning down exactly what changed, but it demonstrates that the ability to use
--gui qtwith mayavi has been broken at some point in the past two years.mwaskom commentedon Jun 15, 2017
Not the be annoying but any progress here? My experience with this issue is that it is a serious regression that has made using mayavi-based tools in an IPython environment extremely difficult.