Fix Mayavi 4.5 QT5 crash by creating virtualenv with QT4

The simple solution for Mayavi 4.5 is to setup a conda environment just for Mayavi. Note that Mayavi 4.5 requires Python 3.5, not Python 3.6.

conda create -n py35 python=3.5 pyqt=4

source activate py35

conda install -c menpo mayavi

test program for Mayavi

from mayavi import mlab;  mlab.show()

should not error.

Test programs for Mayavi. Mayavi should not error with

ImportError: Could not import backend for traits

Discussion of Mayavi setup requirements

The current standard is QT5 for packages involving PyQT (such as Spyder IDE). This is a good thing, especially for high-resolution displays, but it leaves Mayavi 4.5 broken since Mayavi 4.5 prereqs need QT4 AND Python 3.5 (not yet Python 3.6).

Fix Mayavi pyface backend doesn't implement GUI error

If you try Mayavi 4.5 with pyqt5

from mayavi import mlab
mlab.show()

NotImplementedError: the null pyface backend doesn’t implement GUI

to fix, install PyQT 4

conda install pyqt=4

Fix Mayavi RuntimeError: Invalid Qt API 'pyqt5', valid values are: 'pyqt' or 'pyside'

Near the top of the Python script you’re running, add:

import os
os.environ["QT_API"] = "pyqt"

Mayavi plots not displaying

If you’re running on Linux or Windows Subsystem for Linux you need to have an X11 server or Wayland server running (including on WSL).

Leave a Comment