I would like to create some graphics with Python that matplotlib seems to be unable to do well, in terms of drawing closed curves on 3D surfaces. A bit of online research led me to mayavi.mlab for that task (Matplotlib: Plot 3D curve on top of 3D surface). I am currently running Python 3.7.11, but I can upgrade to 3.9 or higher if necessary. I have tried multiple ways to install mayavi and all of them fail in one way or another, including the answers to some of the related questions here. Here are my symptoms:
I tried both conda install mayavi
and conda install -c conda-forge mayavi
from the command line. Both of them have the same problem, which is being unable to "Solve the environment" with "frozen solve". Then it tries a flexible solve and still fails. Then it tries a different repo and again is unable to solve the environment with frozen solve.
I also tried Anaconda Navigator for the same thing, but it hangs during a step called "Solving package dependencies" for about six hours, at which point I stopped it.
Another website told me that pip wheels are more reliable for installing mayavi, but that you should pip install vtk first before mayavi. So I did that: pip install vtk
and then pip install mayavi
. Both seemed to work during install, in the sense that there were no warnings or errors that I could tell. But as soon as I try to import mayavi in a jupyter notebook I get this error:
This looks to my novice eyes like a problem with a Qt interface of some kind, but beyond that I don't know what is going on.
I'm obviously not an expert at Python but I don't know what else to try. Usually conda seems to be able to figure out package dependencies and install what is needed but not this time. I would be happy for any advice, and I apologize in advance if I have left out some important information. Is the problem due to using the anaconda3 version of python 3.7 but installing mayavi with pip? I would prefer to install mayavi with anaconda anyway so I would appreciate any pointers about how to do that.
Installing VTK itself (not just python pip package of vtk) is also a prerequisite for Mayavi.
(MacOS only:)
The following steps install both VTK and Mayavi:
Prerequisites:
brew install llvm
. which requires manual installation steps in brew info llvm
.pip install wheel
# optional. I did it before other steps.Steps:
brew install vtk
# very heavy
pip install vtk
pip install mayavi
(not needed, but for some reason I needed it)
brew install qt5
brew info qt5
# slow
#
Follow instructions of above. (Set PATH
plus LDFLAGS
and CPPFLAGS
for compiler) and close and open the terminal.
qmake
# Test qmake
works on terminal (to test the PATH
of qt5)
pip install pyqt5
# Slow: builds using clang.
export ETS_TOOLKIT=
export QT_API=pyqt5
brew install pyside
# (I installed pyside
too, at earlier steps. It might be unnecessary)
I did many other things as well but this is the steps to reproduce the effective steps. I hope I haven't missed something that I have done (or if there are unnecessary steps). Since it changes the configs, it is difficult to revert back and test from scratch.
This installs the combination of following versions: vtk@9.1
, qt5
.
Also clang
13.1.6 .
Which installs both VTK and Mayavi.
Note, I use venv
, so the exact pip
command may differ for you if you use conda
.
Tested on:
Python: 3.9.13
, MacOS: 12.4 Monterey M1