1
votes

I have been attempting to run the following python code (from Enthought's website) to test the animation capabilities of Enthought's Mayavi module.

from mayavi import mlab
import numpy
n_mer, n_long = 6, 11
pi = numpy.pi
dphi = pi/1000.0
phi = numpy.arange(0.0, 2*pi + 0.5*dphi, dphi, 'd')
mu = phi*n_mer
x = numpy.cos(mu)*(1+numpy.cos(n_long*mu/n_mer)*0.5)
y = numpy.sin(mu)*(1+numpy.cos(n_long*mu/n_mer)*0.5)
z = numpy.sin(n_long*mu/n_mer)*0.5

# View it.
l = mlab.plot3d(x, y, z, numpy.sin(mu), tube_radius=0.025, colormap='Spectral')

# Now animate the data.
ms = l.mlab_source
for i in range(10):
    x = numpy.cos(mu)*(1+numpy.cos(n_long*mu/n_mer +
                                  numpy.pi*(i+1)/5.)*0.5)
    scalars = numpy.sin(mu + numpy.pi*(i+1)/5.)
    ms.set(x=x, scalars=scalars)

However, upon execution, nothing happens. It runs without errors but only the TVTK Scene window pops up blank - no image, no animation. Could the problem lie in the Mayavi module import? The example on the website starts with: from enthought.mayavi import mlab whereas, I have: from mayavi import mlab The 'enthought.mayavi' import string does not work for me. The Mayavi I'm using is a pip installation.
What should I do to fix this? I'm using Mac OSX 10.8.2. Thanks in advance.

2

2 Answers

2
votes

This demo works on my machine (just upgraded to OS 10.8.2).

First thing, though, is to answer your question about the import. Some time around a year and a half ago, we refactored the packages to remove the enthought name from the imports. Thus, the standard way to import mayavi's mlab changed from

from enthought.mayavi import mlab

to

from mayavi import mlab

The setup is designed so that the former still works, but we have attempted to refactor the imports in our example code to the second pattern. Therefore, we can be pretty sure it's not a problem with the import statement.

Have you gotten anything to run in Mayavi yet? Try this:

from mayavi import mlab
mlab.test_plot3d()

Also, what is the version of mayavi, which EPD do you have (32- or 64-bit), and what is the result of the following, in Terminal?

$ echo $ETS_TOOLKIT
0
votes

Using Canopy on Win 7 64 I had a similar problem. Only it displayed the last frame, no animation. I fixed it by changing the pylab backend to wx instead of qt.