Mayavi:AttributeError:模块'mayavi'没有属性'add_module'

时间:2019-05-07 13:23:28

标签: enthought mayavi

我是mayavi的新手,我4天前将其安装在笔记本电脑上。我在这里https://scipy-cookbook.readthedocs.io/items/MayaVi_ScriptingMayavi2_MainModules.html浏览了SciPy Cookbook,并尝试运行第一个示例(ImagePlaneWidget / ScalarCutPlane / SliceUnstructuredGrid模块)

from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane
scp = ScalarCutPlane() # set scp as ScalarCutPlane() module
script.add_module(scp) # add module to the scene
scp.implicit_plane.normal = (1, 0, 0) # set normal to Ox axis
# set origin to (i=10, j=25, k=25) i.e. integers for a structured grid
scp.implicit_plane.origin = (10, 25, 25)
# set origin to (x=1.0, y=2.5, z=2.5) i.e. reals for unstructured grids
# scp.implicit_plane.origin = (1.0, 2.5, 2.5)
scp.implicit_plane.widget.enabled = False
scp.actor.property.diffuse = 0.0 # set some color properties
scp.actor.property.ambient = 1.0 # 
scp.actor.property.opacity = 1.0 #
scp.module_manager.scalar_lut_manager.data_range = [0, 1]

但是我收到以下错误消息:

第2行,在     从enthought.mayavi.modules.scalar_cut_plane导入ScalarCutPlane ImportError:没有名为“ enthought”的模块

在互联网上搜索如何解决此问题时,我遇到了该链接https://sourceforge.net/p/mayavi/mailman/message/34599876/,其中说:“ ....许多旧教程,文档等。 仍然使用enthought.mayavi,但已弃用。您应该使用“ import mayavi”。

因此,我将代码修改如下:

import mayavi
from mayavi.modules.scalar_cut_plane import ScalarCutPlane
scp = ScalarCutPlane() # set scp as ScalarCutPlane() module
mayavi.add_module(scp) # add module to the scene
scp.implicit_plane.normal = (1, 0, 0) # set normal to Ox axis
# set origin to (i=10, j=25, k=25) i.e. integers for a structured grid
scp.implicit_plane.origin = (10, 25, 25)
# set origin to (x=1.0, y=2.5, z=2.5) i.e. reals for unstructured grids
# scp.implicit_plane.origin = (1.0, 2.5, 2.5)
scp.implicit_plane.widget.enabled = False
scp.actor.property.diffuse = 0.0 # set some color properties
scp.actor.property.ambient = 1.0 # 
scp.actor.property.opacity = 1.0 #
scp.module_manager.scalar_lut_manager.data_range = [0, 1]

我再次运行它,但是这次我收到以下错误消息:

第5行,在     mayavi.add_module(scp)#将模块添加到场景 AttributeError:模块'mayavi'没有属性'add_module'

我想删除第4行(我对其进行注释),但是当我这样做并再次运行代码时,我又收到了另一条错误消息:

第15行,在     scp.module_manager.scalar_lut_manager.data_range = [0,1] AttributeError:“ NoneType”对象没有属性“ scalar_lut_manager”

我一直试图使此代码运行,但始终会失败。

可以帮我吗?

欢迎

0 个答案:

没有答案