enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 284 forks source link

tvtk scene windows blank/unresponsive #532

Open ktavabi opened 7 years ago

ktavabi commented 7 years ago

import os
assert(os.environ['ETS_TOOLKIT'] == 'qt4')
from mayavi import mlab
mlab.test_plot3d()

generates blank/unresponsive figure window image

My system info is:

Platform: Linux-4.4.0-87-generic-x86_64-with-debian-stretch-sid Python: 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] Executable: /home/ktavabi/miniconda3/envs/py2.7/bin/python CPU: x86_64: 24 cores Memory: 94.4 GB mne: 0.15.dev0 numpy: 1.13.1 {lapack=mkl_intel_lp64, blas=mkl_intel_lp64} scipy: 0.19.1 matplotlib: 2.0.2 sklearn: 0.18.2 nibabel: 2.1.0 mayavi: 4.5.0 pycuda: 2017.1 skcuda: 0.5.1 pandas: 0.20.3

cc @Eric89GXL

prabhuramachandran commented 7 years ago

Did you set %gui qt? If this is vanilla Python and not IPython you will need to add an mlab.show() at the end. The need to set the gui toolkit is documented at the beginning here: http://docs.enthought.com/mayavi/mayavi/mlab.html

ktavabi commented 7 years ago

I set environment variables ETS_TOOLKIT=qt4 and QT_API=pyqt I am getting following different behaviors:

(1) With ipython

ipython --gui=qt
from mayavi import mlab

returns

ValueError Traceback (most recent call last)

in () ----> 1 from mayavi import mlab /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/mayavi/mlab.py in () 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 /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/mayavi/tools/camera.py in () 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 /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/mayavi/tools/engine_manager.py in () 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 /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/mayavi/preferences/api.py in () 2 3 # The global PreferenceManager instance ----> 4 from .preference_manager import preference_manager 5 from .bindings import set_scene_preferences, get_scene_preferences /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/mayavi/preferences/preference_manager.py in () 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) /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/traitsui/api.py in () 34 35 try: ---> 36 from .editors.api import ArrayEditor 37 except ImportError: 38 # ArrayEditor depends on numpy, so ignore if numpy is not present. /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/traitsui/editors/__init__.py in () 21 22 try: ---> 23 from .api import ArrayEditor 24 except ImportError: 25 pass /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/traitsui/editors/api.py in () 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 /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/traitsui/editors/code_editor.py in () 34 #------------------------------------------------------------------------------- 35 ---> 36 class ToolkitEditorFactory ( EditorFactory ): 37 """ Editor factory for code editors. 38 """ /home/ktavabi/miniconda3/envs/py2.7/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) /home/ktavabi/miniconda3/envs/py2.7/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 ): /home/ktavabi/miniconda3/envs/py2.7/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 ) /home/ktavabi/miniconda3/envs/py2.7/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 ): /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/traitsui/toolkit.pyc in toolkit(*toolkits) 150 if ETSConfig.toolkit: 151 # If a toolkit has already been set for ETSConfig, then use it: --> 152 _toolkit = _import_toolkit(ETSConfig.toolkit) 153 return _toolkit 154 else: /home/ktavabi/miniconda3/envs/py2.7/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 /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/traitsui/qt4/__init__.py in () 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 #---------------------------------------------------------------------------- /home/ktavabi/miniconda3/envs/py2.7/lib/python2.7/site-packages/pyface/qt/__init__.py in () 38 39 elif qt_api == 'pyqt': ---> 40 prepare_pyqt4() 41 42 elif qt_api != 'pyside': /home/ktavabi/miniconda3/envs/py2.7/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 1

So far neither from pyface.qt import QtGui, QtCore or unsetting QT_API resolve this.

(2) In a regular python console

from mayavi import mlab
mlab.test_plot3d()

works!

(3) In a Pycharm IDE python console

from mayavi import mlab
mlab.test_plot3d()
mlab.show()

Is necessary for snippet to work.

prabhuramachandran commented 7 years ago

So on IPython it appears that IPython is setting the version to 2. Can you try this:

$ ipython

from mayavi import mlab
%gui qt
mlab.test_plot3d()

Maybe this will set the QT API to 2 before IPython can set it to 1. Technically and according to the IPython docs here: http://ipython.readthedocs.io/en/stable/interactive/reference.html#pyqt-and-pyside this should not happen but lets see.

ktavabi commented 7 years ago

Thank you @prabhuramachandran that did the trick...for now.

It would be nice if the state of affair between backends, bindings, and viz modules wasn't so fluid. So I am currently trying to adopt a practice working with virtual envs for projects that I intend (or hope) to freeze in a working state. That said in my experience for any given update or install e.g., ipython or matplotlib there is no guarantee the visualization stack remains intact. Perhaps that's just my naivete, but I have to admit I do spend a great deal of time troubleshooting and fixing broken things 😞 So I am always curious to hear about how developers tend to keep their 'environment' in working order.

FYI cc @kingjr @choldgraf @Eric89GXL

choldgraf commented 7 years ago

So I am always curious to hear about how developers tend to keep their 'environment' in working order.

prabhuramachandran commented 7 years ago

@choldgraf -- LOL!

@kambysese -- Well, our own code hasn't really changed much. The issue is that there is pyside, pyqt, pyqt4, pyqt5, qtdate (and whatnot), wxPython (2, 3, now 4!). I think we should just document this carefully somewhere. Do you have a suggestion? Would putting it here: http://docs.enthought.com/mayavi/mayavi/mlab.html be OK?

ktavabi commented 6 years ago

@prabhuramachandran Why is this now happening on OSX? regardless of %gui qt magic

screen shot 2018-04-25 at 11 05 30 am
prabhuramachandran commented 6 years ago

No idea, things haven been working well for me. What version of PyQt5? PyQt5 isn't as stable as I'd like, I've had strange problems very so often. PyQt5 (5.10.1) works for me on OSX but crashes on Windows where I've needed to downgrade to 5.9.2.

ktavabi commented 6 years ago

I am using PyQt 5.9.2

prabhuramachandran commented 6 years ago

Interesting, it used to work for me but the toolbar would float all over the place, upgrading to PyQt 5.10.1 fixed it for me. However, I would get a working visualization, it was only the toolbar that was messed up. Try updating to PyQt5.10.1.

ktavabi commented 6 years ago

conda isn't happy with that option due to dependencies. I can try but I am pretty sure something else will break.

prabhuramachandran commented 6 years ago

I have been using pip install PyQt5.

ktavabi commented 6 years ago

nvmd 5.9.2 is the highest version available on default conda channel.

larsoner commented 6 years ago

I can confirm with 5.9.4 the window shows nothing on OSX, with:

pip install pyqt5 --upgrade --no-deps

It upgrades to 5.10.1 it works.

prabhuramachandran commented 6 years ago

@larsoner -- thanks! What a pain. Don't use 5.10.1 on windows especially on appveyor.