Despite using mayavi for a long time, I still run into problem when reinstalling mayavi. Thus, I wrote this guide on how to install mayavi and solutions to some errors that I collected.
Install mayavi using pip
- Create conda environment to install mayavi with python 3.7 (I haven’t tested other python version)
conda create -y -n mayavi python=3.7 conda activate mayavi
- Install numpy, which is required by mayavi
pip install numpy
- Following the official instruction to install mayavi
pip install mayavi pip install PyQt5
- Set the correct ETS_TOOLKIT following the suggestion in this comment
export ETS_TOOLKIT=qt4 export QT_API=pyqt5
Optional: You might need to put these lines in ~/.bashrc and run
source ~/.bashrc. These variables will be set automatically everytime you boot the computer.
If you forget to set these variables ETS_TOOLKIT and QT_API, mayavi will return the following error:
Traceback (most recent call last): File "/home/acao/miniconda3/envs/mayavi/lib/python3.7/site-packages/tvtk/pyface/ui/qt4/scene.py", line 60, in resizeEvent self._scene._renwin.update_traits() AttributeError: 'NoneType' object has no attribute 'update_traits' Aborted (core dumped)
Install mayavi using conda
- Install mayavi using conda:
conda install -c anaconda mayavi
- Install numba:
pip install numba==0.53
- Install TBB version 2020.2:
conda install -c bioconda tbb=2020.2
These steps were suggested in this comment.
pip install mayavifails at building wheel for mayavi. This error was pointed out in this comment. The reason is that the version of vtk is too new. Thus, the solution is to downgrade vtk version to 8.1.2:
pip install PyQt5 pip install VTK==8.1.2 pip install mayavi
If you have trouble defining programatically the viewpoint in Mayavi, you can take a look at my post: How to define viewpoint programmatically in Mayavi.