Python包安装——mayavi安装

深圳爱智慧科技有限公司 深度学习 人工智能 智能投顾 机器学习 中国版kensho 深圳爱智慧科技有限公司html


安装mayavi有两种方法:python

一种是安装集成了多个python包的软件,如 Enthought CanopyPythonxy, orAnaconda.可是貌似几个集成环境中都没有看到mayavi的影子。git

第二种就是从源代码开始安装:安装mayavi以前先要安装这几个依赖包github

You must have the following libraries installed before installing the Mayavi project:api

那么先开始安装vtk吧。两种方法:

一:app

首先安装vtk:less

安装VTK,从网站http://www.vtk.org/VTK/resources/software.html 下载最新版本,此文安装的是:vtkpython-6.1.0-Windows-64bit.exepython2.7

3)配置VTK环境变量:机器学习

A:把VTK中的bin文件加入系统变量中:如:PATH:C:\Program Files\VTK 6.1.0\binide

B:设置python路径,在系统变量中建立PYTHONPATH :如:PYTHONPATH :C:\Program Files\VTK 6.1.0\bin;C:\Program Files\VTK 6.1.0\bin\Lib\site-packages

4)测试,打开python IDEL界面,输入:import vtk

>>> import vtk
>>> 

没报错,就说明安装成功了。

我是直接把site-packages里面的vtk拷贝到了python27下面的site-packages中


安装VTK的第二种方法,从源代码开始安装(须要先编译VTK,因为是win10系统没成功



好吧,装了了vtk以后再到mayavi-4.4.3文件夹下运行python setup.py install 仍是不成功。


因而又老老实实看了Enthought Canopy发现vtk,tvtk还有traits啥的仍是有的,尽管就是没有mayavi,先装个Canopy,而后把site-packages里面的vtk拷贝到了python27下面的site-packages中


我擦,不科学,怎么会这样




特么居然有了,有了!!!!!!直接考到python27下面的site-packages中

import mayavi.mlab as mlab

遇到ValueError: cannot set toolkit to wx because it has already been set to qt4的问题

从这个网址看到的解决方案

Hi, 

Building traitsui GUIs from the ipython notebook should work the same as from a regular ipython console. The difference between configure_traits and edit_traits is that the first one creates a GUI event loop before building the traitsUI window in it. That's what makes it responsive or not. Alternatively you can manually start the GUI event loop by specifying --gui=?? when you create ipython, for example:
ipython notebook --gui=wx
Then you should use edit_traits() and the UI element will be responsive. 

Finally, ETSConfig allows you to set the backend at your script runtime instead of when you start python/ipython. This is what I do the most so that I don't need to set the value of the ETSConfig environment variable, or set the gui switch when starting python/ipython.

To conclude, the following code is what I do the most and works from within the ipython notebook started with ipython notebook (version 0.13):
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'

from traits.api import HasTraits, Enum
from traitsui.api import View

class A(HasTraits):
    x = Enum(["foo","bar"])

a = A()
a.configure_traits()

HTH, 
Jonathan



Thanks, Jonathan.


I would like to follow your advice, but am getting some errors. When I try this at the top of a new notebook, I get:

from traits.api import *
from traits.etsconfig.api import ETSConfig
from traitsui.api import *
ETSConfig.toolkit = 'qt4'

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-8a5daaa83ef1> in <module>()
----> 1 ETSConfig.toolkit = 'qt4'

/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/traits/etsconfig/etsconfig.py in _set_toolkit(self, toolkit)
 208         if self._toolkit and self._toolkit != toolkit:
 209             raise ValueError, "cannot set toolkit to %s because it has "\
--> 210 "already been set to %s" % (toolkit, self._toolkit)
 211 
 212         self._toolkit = toolkit

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

Any idea what might be causing this? I suspect the other error below on starting ipython-qtconsole may be related, but am equally clueless about this. I think both these worked until recently. 

Ah, Google to the rescue

I must put ETSConfig.toolkit = 'qt4' before any other ETS import, or the earlier import will set default to wx. 

The corresponding ipython-qtconsole error happened because I still had an ipython notebook server open in which the same error had already happened, seems OK now.

Why one uses 2.6 and the other 2.7 I don't even need to know, as long as it works :-)

All set now, thank you!


================================================================================================================================

下面是一个例子

import numpy as np
import mayavi . mlab as mlab
import    moviepy . editor as mpy
 
duration = 2 # duration of the animation in seconds (it will loop)
 
# MAKE A FIGURE WITH MAYAVI
 
fig = mlab . figure ( size = ( 500 , 500 ) , bgcolor = ( 1 , 1 , 1 ) )
 
u = np . linspace ( 0 , 2 * np . pi , 100 )
xx , yy , zz = np . cos ( u ) , np . sin ( 3 * u ) , np . sin ( u ) # Points
l = mlab . plot3d ( xx , yy , zz , representation = "wireframe" , tube_sides = 5 ,
                 line_width = . 5 , tube_radius = 0.2 , figure = fig )
 
# ANIMATE THE FIGURE WITH MOVIEPY, WRITE AN ANIMATED GIF
 
def make_frame ( t ) :
     """ Generates and returns the frame for time t. """
     y = np . sin ( 3 * u ) * ( 0.2 + 0.5 * np . cos ( 2 * np . pi * t / duration ) )
     l . mlab_source . set ( y = y ) # change y-coordinates of the mesh
     mlab . view ( azimuth = 360 * t / duration , distance = 9 ) # camera angle
     return mlab . screenshot ( antialiased = True ) # return a RGB image
 
animation = mpy . VideoClip ( make_frame , duration = duration ) . resize ( 0.5 )
# Video generation takes 10 seconds, GIF generation takes 25s
animation . write_videofile ( "wireframe.mp4" , fps = 20 )
animation . write_gif ( "wireframe.gif" , fps = 20 )


运行这个例子提醒没有安装“ffmpeg.win32.exe”

从https://github.com/imageio/imageio-binaries/blob/master/ffmpeg/ffmpeg.win32.exe下载了个ffmpeg.win32.exe”文件。

而后在用户和系统环境变量里面新建一个名字叫“IMAGEIO_FFMPEG_EXE”,值是你存放这个exe文件的地址的变量。