-
安装参考链接:https://blog.csdn.net/ksearch/article/details/21728335#
-
python使用windows+R后输入cmd打开命令行;
-
在命令行中输入Pip install -i https://pypi.tuna.tsinghua.edu.cn/simple mayavi
-
这里目测是安装成功。进行代码测试:
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()
ImportError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_5896\339902131.py in <module>
----> 1 s = mlab.mesh(x, y, z)
2 mlab.show()
d:\python\python37\lib\site-packages\mayavi\tools\helper_functions.py in the_function(*args, **kwargs)
36
37 def the_function(*args, **kwargs):
---> 38 return pipeline(*args, **kwargs)
39
40 if hasattr(pipeline, 'doc'):
d:\python\python37\lib\site-packages\mayavi\tools\helper_functions.py in __call__(self, *args, **kwargs)
76 scene = getattr(figure, 'scene', None)
77 else:
---> 78 scene = tools.gcf().scene
79 if scene is not None:
80 self._do_redraw = not scene.disable_render
d:\python\python37\lib\site-packages\mayavi\tools\figure.py in gcf(engine)
112 """
113 if engine is None:
--> 114 engine = get_engine()
115 scene = engine.current_scene
116 if scene is None:
d:\python\python37\lib\site-packages\mayavi\tools\engine_manager.py in get_engine(self)
90 if e.__class__.__name__ == 'Engine']
91 if len(suitable) == 0:
---> 92 return self.new_engine()
93 else:
94 # Return the most engine add to the list most recently.
d:\python\python37\lib\site-packages\mayavi\tools\engine_manager.py in new_engine(self)
135 options.
136 """
--> 137 check_backend()
138 if options.backend == 'envisage':
139 from mayavi.plugins.app import Mayavi
d:\python\python37\lib\site-packages\mayavi\tools\engine_manager.py in check_backend()
38 have a suitable UI toolkit like PyQt/PySide or wxPython
39 installed.'''
---> 40 raise ImportError(msg)
41
42
ImportError: Could not import backend for traitsui. Make sure you
have a suitable UI toolkit like PyQt/PySide or wxPython
installed.
- 运行报错,目测是缺少了包,查询得到缺少GUI可视化包,安装wxpython或者pyqt,随便你选,区别在下面这个链接里wxpython与pyqt区别
- 我安装了wxpython
Pip install -i https://pypi.tuna.tsinghua.edu.cn/simple wxpython
- 展示!!!