Repository: spyder-ide/spyder

Issue:
Plotting with Mayavi is broken
Hi,
for me since the last update from 3.2.5 -> 3.2.6, graphics with mayavi is broken somehow.
Using mayavi in a plain IPython terminal works for me. 
Downgrading spyder to 3.2.5 gets things back to normal.
With 3.2.6 and on startup I get

Issue #1----------------------------

Python 3.5.4 | packaged by conda-forge | (default, Dec  9 2017, 16:18:50)
Type "copyright", "credits" or "license" for more information.
IPython 6.2.1 -- An enhanced Interactive Python.
NOTE: Spyder *can't* set your selected Matplotlib backend because there is a previous backend already in use.
Your backend will be Qt4Agg
In [1]: 

I've seen reports of this strange NOTE: ... elsewhere. I don't know if I should worry and if it is related to the mayavi issue. I am using a Python 3.5.x environment in Anaconda with pyqt 4.11.4, since mayavi is known not to work with Python 3.6.x and Qt5 (...and it also never did for me)

Issue #2-------------------------------
Now, when trying to import mayvi's mlab module, I get

In [1]: from mayavi import mlab as ml
Changing backend to Qt for Mayavi
Traceback (most recent call last):

  File "<ipython-input-1-7c9ecc7223f4>", line 1, in <module>
    from mayavi import mlab as ml

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/mayavi/mlab.py", line 27, in <module>
    from mayavi.tools.camera import view, roll, yaw, pitch, move

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/mayavi/tools/camera.py", line 25, in <module>
    from .engine_manager import get_engine

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/mayavi/tools/engine_manager.py", line 12, in <module>
    from mayavi.preferences.api import preference_manager

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/mayavi/preferences/api.py", line 4, in <module>
    from .preference_manager import preference_manager

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/mayavi/preferences/preference_manager.py", line 29, in <module>
    from traitsui.api import View, Group, Item

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/api.py", line 36, in <module>
    from .editors.api import ArrayEditor

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/editors/__init__.py", line 23, in <module>
    from .api import ArrayEditor

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/editors/api.py", line 24, in <module>
    from .code_editor import CodeEditor

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/editors/code_editor.py", line 36, in <module>
    class ToolkitEditorFactory ( EditorFactory ):

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/editors/code_editor.py", line 48, in ToolkitEditorFactory
    mark_color = Color( 0xECE9D8 )

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traits/traits.py", line 522, in __call__
    return self.maker_function( *args, **metadata )

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traits/traits.py", line 1236, in Color
    return ColorTrait( *args, **metadata )

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/toolkit_traits.py", line 7, in ColorTrait
    return toolkit().color_trait( *args, **traits )

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/toolkit.py", line 161, in toolkit
    _toolkit = _import_toolkit(toolkit_name)

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/toolkit.py", line 83, in _import_toolkit
    return __import__( name, globals=globals(), level=1 ).toolkit

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/traitsui/qt4/__init__.py", line 18, in <module>
    import pyface.qt

  File "/home/userxyz/.anaconda3/envs/py35/lib/python3.5/site-packages/pyface/qt/__init__.py", line 44, in <module>
    % qt_api)

RuntimeError: Invalid Qt API 'pyqt5', valid values are: 'pyqt' or 'pyside'


In [2]: 

---------------------------------------------------------------
## Versions and main components
Python 3.5.4 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.4 on Linux 

## Dependencies
IPython >=4.0    :  6.2.1 (OK)
cython >=0.21    :  0.27.3 (OK)
jedi >=0.9.0     :  0.11.1 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.12.1 (OK)
pandas >=0.13.1  :  None (NOK)
psutil >=0.3     :  5.4.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.8.1 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.6.6 (OK)
sympy >=0.7.3    :  None (NOK)

Greetings, Xaver


Discussion:
Thanks for reporting. We'll take a look at this in a future release.
Just for completeness, did you try with the different matplotlib backends, if that's relevant?

Resolving patch:
diff --git a/spyder/utils/site/sitecustomize.py b/spyder/utils/site/sitecustomize.py
--- a/spyder/utils/site/sitecustomize.py
+++ b/spyder/utils/site/sitecustomize.py
@@ -242,6 +242,8 @@ def _getfilesystemencoding_wrapper():
             sip.setapi(qtype, 2)
     except:
         pass
+else:
+    os.environ.pop('QT_API')
 
 
 #==============================================================================
diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py
--- a/spyder/widgets/ipythonconsole/shell.py
+++ b/spyder/widgets/ipythonconsole/shell.py
@@ -427,9 +427,9 @@ def set_backend_for_mayavi(self, command):
                     calling_mayavi = True
                     break
         if calling_mayavi:
-            message = _("Changing backend to Qt for Mayavi")
+            message = _("Changing backend to Qt4 for Mayavi")
             self._append_plain_text(message + '\n')
-            self.silent_execute("%gui inline\n%gui qt")
+            self.silent_execute("%gui inline\n%gui qt4")
 
     def change_mpl_backend(self, command):
         """


Test patch: