Monday, September 3, 2012

Mayavi2 import problems in Ubuntu 10.04, python 2.6.5


Recently I was trying to import mayavi2 into python 2.6.5 on Ubuntu 10.04
Mayavi2 can be downloaded and installed using:

sudo apt-get install mayavi2

From there when I tried to import it into python using the line in the tutorials:

import mayavi

I would get the error msg:

Traceback (most recent call last):
  File "", line 1, in
ImportError: No module named mayavi


After a little searching through the installed files I tried

import enthought.mayavi

That did the trick.  You can test it using the exmple posted here:

http://docs.enthought.com/mayavi/mayavi/mlab.html


Here is the code with my slight modification. 

from numpy import pi, sin, cos, mgrid
dphi, dtheta = pi/250.0, pi/250.0
[phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
x = r*sin(phi)*cos(theta)
y = r*cos(phi)
z = r*sin(phi)*sin(theta)

# View it.
from enthought.mayavi import mlab
s = mlab.mesh(x, y, z)
mlab.show()

No comments:

Post a Comment