Reputation: 5128
I tried to setup Mayavi on macOS (currently running Sierra) using the following:
brew install --with-qt5 vtk
brew install mayavi
This should theoretically work but now when I try to use Mayavi in my code I get the following error:
Traceback (most recent call last):
File "test.py", line 32, in <module>
mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(400, 300))
File "/usr/local/lib/python2.7/site-packages/mayavi/tools/figure.py", line 63, in figure
engine = get_engine()
File "/usr/local/lib/python2.7/site-packages/mayavi/tools/engine_manager.py", line 101, in get_engine
return self.new_engine()
File "/usr/local/lib/python2.7/site-packages/mayavi/tools/engine_manager.py", line 146, in new_engine
check_backend()
File "/usr/local/lib/python2.7/site-packages/mayavi/tools/engine_manager.py", line 49, in check_backend
''')
ImportError: Could not import backend for traits
_______________________________________________________________________________
Make sure that you have either the TraitsBackendWx or the TraitsBackendQt
projects installed. If you installed Mayavi with easy_install, try
easy_install <pkg_name>. easy_install Mayavi[app] will also work.
If you performed a source checkout, be sure to run 'python setup.py install'
in Traits, TraitsGUI, and the Traits backend of your choice.
Also make sure that either wxPython or PyQT is installed. wxPython:
http://www.wxpython.org/ PyQT:
http://www.riverbankcomputing.co.uk/software/pyqt/intro
I belive the error lies in the fact that Homebrew only supports Qt5 and PyQT5 while Mayavi is looking for PyQT4 in the background. Is there a way to get Mayavi to work with PyQT5 or is there a way to install PyQT4 with brew
?
And of course the problem could lie elsewhere....
Thanks!
Upvotes: 1
Views: 1398
Reputation: 5392
I would recommend against using wx; I've run into a mess of issues getting it to run Mayavi examples (not to mention incompatibility with virtual environments). And from the mayavi repo:
Mayavi itself should work with the new wxPython 4.x. However, traitsui, pyface, and other ETS packages do not yet support it so the UI will not work correctly. Older versions should work. PyQt/PySide should work largely out of the box.
Here's how to install Mayavi w/ PyQt4 on macOS Sierra+:
brew install vtk
brew tap cartr/qt4
brew tap-pin cartr/qt4
brew install cartr/qt4/qt
brew install cartr/qt4/pyqt
brew install pyside
pip install mayavi
These steps make sure you get v4, not the default v5. And you may want to do unset ETS_TOOLKIT
to make sure mayavi doesn't look for a different backend.
FWIW PyQt5 is not available (at least as a PyPI package) for Python 2x -- I see you're running Python 2.7. You can do pip3 PyQt5
, but mayavi dependencies will need extra setup for Python 3 -- specifically pip3 install traitsui
.
Upvotes: 1
Reputation: 7293
An alternative is to use wx instead of qt, see the docs here: docs.enthought.com/mayavi/mayavi/installation.html
Then, set the environment variable export ETS_TOOLKIT=wx - it is worth a try.
Upvotes: 1