Fix Mayavi 4.5 QT5 crash by creating virtualenv with QT4

1 minute read

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

conda activate py35

conda install -c menpo mayavi

Plot 3-D data

Using Mayavi, Matplotlib or more advanced modules, one can make very high quality, manipulable volume plots. Create a file with the content

from mayavi import mlab
import numpy as np

x, y, z = np.mgrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)


Mayavi Error fix

If you an error about the incorrect number of arguments, try this one-line Mayavi patch fix:

test program for Mayavi

from mayavi import mlab

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

and get:

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