编程语言
首页 > 编程语言> > python-如何解决“ TraitError:…实例的’input’特性是’只读’.”

python-如何解决“ TraitError:…实例的’input’特性是’只读’.”

作者:互联网

与vtk的原始Python API相比,我一直更喜欢pythonic tvtk,但是使用从MacPorts获得的最新版本,我遇到了基本问题不再起作用的问题.以下代码段摘自tvtv documentation

from tvtk.api import tvtk
cs = tvtk.ConeSource()
cs.resolution = 36
m = tvtk.PolyDataMapper()
m.input = cs.output # <== fails here
a = tvtk.Actor()
a.mapper = m
p = a.property
p.representation = 'w'
print p.representation

每次初始化“输入”特征时,都会出现类似

TraitError: The 'input' trait of a PolyDataMapper instance is 'read only'.

我发现了许多类似的问题,错误报告等,但它们都指向与VTK 6(SetInputData和SetInputConnection而不是SetInput)有关的更改,而我有should be supported in Mayavi 4.4.2

vtk @6.3.0_0+python27 (active)
py27-traits @4.5.0_0 (active)
py27-traitsui @5.0.0_0 (active)
py27-apptools @4.3.0_0 (active)
py27-envisage @4.4.0_0 (active)
py27-pyface @5.0.0_0+pyqt4 (active)
py27-mayavi @4.4.3_0 (active)

PolyDataMapper具有以下输入特征:

'input': <traits.traits.CTrait at 0x11b23a260>,
'input_algorithm': <traits.traits.CTrait at 0x119516520>,
'input_as_data_set': <traits.traits.CTrait at 0x11b230470>,
'input_connection': <traits.traits.CTrait at 0x119516310>,
'input_executive': <traits.traits.CTrait at 0x1195165d0>,
'input_information': <traits.traits.CTrait at 0x119516680>,

解决方法:

Mayavi支持VTK 5.10和VTK 6.x,它们内部具有用于配置到管道的不同API. tvtk软件包具有一个公共API,该API支持两个版本以实现可移植性.

变更:

m.input = cs.output # <== fails here

至:

from tvtk.common import configure_input
tvtk.configure_input(m, cs) # <== will work

参考:https://github.com/enthought/mayavi/blob/master/tvtk/common.py#L79

标签:mayavi,macports,enthought,python
来源: https://codeday.me/bug/20191119/2033556.html