Mayavi Python easy install

Mayavi may be thought of as a Python layer atop VTK, making common 3-D data plotting tasks easy. Mayavi is installed via pip or conda. VTK, Traits, et al have .whl binary wheel wheels, which avoid the previously painful build process.


Because of the large number of prereq packages for Mayavi, we strongly urge installing Mayavi in a seperate virtualenv or Conda environment.

Note: we specify Python 3.7 as that’s currently the newest version VTK has a conda package for.

conda create -n vis3d python==3.7

conda activate vis3d

conda install mayavi

Plot 3-D data

Mayavi makes 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)

scf = mlab.pipeline.scalar_field(x,y,z,s)

Test programs for Mayavi. Mayavi should not error with

ImportError: Could not import backend for traits


There may be spurious errors during install such as:

ModuleNotFoundError: No module named ‘vtk’

but Mayavi usually works anyway.

Mayavi plots not displaying

On Linux or Windows Subsystem for Linux an X11 server or Wayland server is necessary.