Search code examples
pythonmatplotlibwxpythonmayavi

MayaVi ValueError, how to run with wx backend?


At this point, I'm just trying to get started with using MayaVi, but can not get it to run from within Python shell/scripts. The MayaVi GUI does work, however.

I'm trying to run some of the examples I found online (e.g. [1]), however when I attempt to run them, I get the seemingly ubiquitous error (e.g. [2], [3]) of:

Value Error: cannot set toolkit to wx because it has already been set to qt4

The solutions to the above referenced SO threads all seem to be: discard wx and use qt4. However, I'm ultimately interested in embedding my visualizations into a wxPython application, and thus would like to use wx!

I have tried adding:

import matplotlib
matplotlib.use('WxAgg')

to the beginning of the example script, but that does not solve the issue.

I am running:

  • Windows 7, 64 Bit
  • Enthought Canopy Python 2.7.6 (64 bit)
  • wxPython 3.0.2.0
  • mayavi 4.4.3
  • matplotlib 1.5.1

Unsure what else (if anything) may be relevant.

Is there a solution where I can run mayavi with wx?


Solution

  • Sometimes, it's the most obvious solution. As suggested in the referenced SO solutions, rather than setting ETS_TOOLKIT = "qt4", just need to set it to "wx". I do this within the script (at the start) with:

    import os
    os.environ['ETS_TOOLKIT'] = 'wx'
    

    And it works fine!