Mayavi 4.6 easy install

1 minute read

Mayavi 4.6 and VTK 8 use QT5 and finally are pip installable, which makes the install process much easier than before. VTK, Traits, et al now have .whl wheels, which avoid the previously painful build process. Install Mayavi simply by:

python -m pip install mayavi

You may get spurious error during install, disregard it.

ModuleNotFoundError: No module named ‘vtk’

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)


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


These comments are archived for OBSOLETE Mayavi 4.5. They are NOT relevant to Mayavi ≥ 4.6.

Mayavi 4.5 prereqs need QT4 AND Python 3.5.

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).

Mayavi Error fix

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

Leave a comment