Python错误“;TypeError:sort()最多接受2个参数(给定3个)";

Python错误“;TypeError:sort()最多接受2个参数(给定3个)";,python,numpy,image-processing,3d,mayavi,Python,Numpy,Image Processing,3d,Mayavi,在运行以下脚本时,我收到“TypeError:sort()最多接受2个参数(给定3个)”: 我使用的python、numpy和mayavi版本分别是3.5.2(Anaconda4.1.1)、1.11.1和4.5.0。Mayavi是使用以下命令安装的: conda install --channel https://conda.anaconda.org/menpo mayavi 我已经尝试了mayavi的一些其他API,它们工作得很好。有人知道什么地方可能出了问题吗?下面是完整的回溯 -----

在运行以下脚本时,我收到“TypeError:sort()最多接受2个参数(给定3个)”:

我使用的python、numpy和mayavi版本分别是3.5.2(Anaconda4.1.1)、1.11.1和4.5.0。Mayavi是使用以下命令安装的:

conda install --channel https://conda.anaconda.org/menpo mayavi
我已经尝试了mayavi的一些其他API,它们工作得很好。有人知道什么地方可能出了问题吗?下面是完整的回溯

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-6743e5b203bd> in <module>()
----> 1 mlab.pipeline.volume(sf)

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe_base.py in the_function(*args, **kwargs)
     36 def make_function(factory_class):
     37     def the_function(*args, **kwargs):
---> 38         factory = factory_class(*args, **kwargs)
     39         return factory._target
     40 

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe_base.py in __init__(self, parent, **kwargs)
    144             self._do_redraw = not scene.disable_render
    145             scene.disable_render = True
--> 146         if issubclass(self._target.__class__, Filter):
    147             self._engine.add_filter(self._target, obj=parent)
    148         else:

C:\Anaconda3\lib\site-packages\traits\trait_types.py in create_default_value(self, *args, **kw)
   2799                 raise TraitError('Unable to locate class: ' + args[0])
   2800 
-> 2801         return klass( *args[1:], **kw )
   2802 
   2803     #: fixme: Do we still need this method using the new style?...

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\core\module.py in __init__(self, **traits)
     56 
     57         # Let the module setup its pipeline.
---> 58         self.setup_pipeline()
     59 
     60     def __get_pure_state__(self):

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in setup_pipeline(self)
    305         vp = self._volume_property = tvtk.VolumeProperty()
    306 
--> 307         self._ctf = ctf = default_CTF(0, 255)
    308         self._otf = otf = default_OTF(0, 255)
    309         vp.set_color(ctf)

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in default_CTF(x1, x2)
    123                     val_range=(1.0, 1.0),
    124                     n=10,
--> 125                     mode='sqrt')
    126 
    127 

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in make_CTF(x1, x2, hue_range, sat_range, val_range, n, mode)
    101             v = val_range[0] + dval*x
    102             r, g, b, a = [sqrt(c) for c in hsva_to_rgba(h, s, v, 1.0)]
--> 103             ctf.add_rgb_point(mins+x*ds, r, g, b)
    104     elif mode == 'linear':
    105         for i in range(n+1):

c:\anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\tvtk\util\ctf.py in add_rgb_point(self, *args)
    208         ret = super(ColorTransferFunction, self).add_rgb_point(*args)
    209         self.nodes.append(args[0])
--> 210         self.nodes.sort()
    211         return ret
    212 

C:\Anaconda3\lib\site-packages\traits\trait_handlers.py in sort(self, cmp, key, reverse)
   2565     def sort ( self, cmp = None, key = None, reverse = False ):
   2566         removed = self[:]
-> 2567         list.sort( self, cmp = cmp, key = key, reverse = reverse )
   2568 
   2569         if (getattr(self, 'name_items', None) is not None and

TypeError: sort() takes at most 2 arguments (3 given)
*********************************************************************************
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1百万磅管道容积(平方英尺)
C:\Anaconda3\lib\site packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe\u base.py在函数中(*args,**kwargs)
36 def制造功能(工厂级):
37定义_函数(*args,**kwargs):
--->38工厂=工厂等级(*args,**kwargs)
39返回工厂。\u目标
40
C:\Anaconda3\lib\site packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe\u base.py in\uuuuuuuuuu init\uuuuuuuuuuuuu(self,parent,**kwargs)
144 self.\u do\u redraw=非场景。禁用\u渲染
145 scene.disable_render=True
-->146如果发布类(自身目标类过滤器):
147 self.\u引擎。添加过滤器(self.\u目标,obj=父级)
148.其他:
C:\Anaconda3\lib\site packages\traits\trait\u types.py在create\u default\u值(self,*args,**kw)中
2799错误('无法定位类:'+args[0])
2800
->2801返回klass(*参数[1:],**kw)
2802
2803#:fixme:我们还需要使用这种新样式的方法吗?。。。
C:\Anaconda3\lib\site packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\core\module.py in uuuuu init_uuu(self,**traits)
56
57#让模块设置其管道。
--->58.自我设置_管道()
59
60定义获得纯状态(自身):
C:\Anaconda3\lib\site packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py安装管道(self)
305 vp=self.\u volume\u property=tvtk.VolumeProperty()
306
-->307 self.\u ctf=ctf=default\u ctf(0255)
308 self.\u otf=otf=default\u otf(0255)
309 vp.设置颜色(ctf)
默认情况下C:\Anaconda3\lib\site packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py(x1,x2)
123 val_范围=(1.0,1.0),
124 n=10,
-->125模式(='sqrt')
126
127
C:\Anaconda3\lib\site packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in make_CTF(x1、x2、色调范围、饱和度范围、量程范围、n、模式)
101 v=量程[0]+dval*x
102 r,g,b,a=[hsva_至_rgba(h,s,v,1.0)中c的sqrt(c)]
-->103 ctf.添加rgb点(分钟+x*ds、r、g、b)
104 elif模式==‘线性’:
范围(n+1)内的i为105:
c:\anaconda3\lib\site packages\mayavi-4.5.0-py3.5-win-amd64.egg\tvtk\util\ctf.py in add_rgb_point(self,*args)
208 ret=super(颜色传递函数,自)。添加点(*args)
209 self.nodes.append(参数[0])
-->210 self.nodes.sort()
211返回ret
212
C:\Anaconda3\lib\site packages\traits\trait\u handlers.py排序(self、cmp、key、reverse)
2565 def排序(自、cmp=None、key=None、reverse=False):
2566已移除=自身[:]
->2567 list.sort(self,cmp=cmp,key=key,reverse=reverse)
2568
2569如果(getattr(self,'name_items',None)不是None,则
TypeError:sort()最多接受2个参数(给定3个)
*********************************************************************************

显然你的
traits
版本不支持Python 3。

谢谢!我升级了traits,它现在似乎正常工作。我仍然收到一条警告消息,但这似乎与VTK有关,而不是traits。
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-6743e5b203bd> in <module>()
----> 1 mlab.pipeline.volume(sf)

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe_base.py in the_function(*args, **kwargs)
     36 def make_function(factory_class):
     37     def the_function(*args, **kwargs):
---> 38         factory = factory_class(*args, **kwargs)
     39         return factory._target
     40 

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe_base.py in __init__(self, parent, **kwargs)
    144             self._do_redraw = not scene.disable_render
    145             scene.disable_render = True
--> 146         if issubclass(self._target.__class__, Filter):
    147             self._engine.add_filter(self._target, obj=parent)
    148         else:

C:\Anaconda3\lib\site-packages\traits\trait_types.py in create_default_value(self, *args, **kw)
   2799                 raise TraitError('Unable to locate class: ' + args[0])
   2800 
-> 2801         return klass( *args[1:], **kw )
   2802 
   2803     #: fixme: Do we still need this method using the new style?...

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\core\module.py in __init__(self, **traits)
     56 
     57         # Let the module setup its pipeline.
---> 58         self.setup_pipeline()
     59 
     60     def __get_pure_state__(self):

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in setup_pipeline(self)
    305         vp = self._volume_property = tvtk.VolumeProperty()
    306 
--> 307         self._ctf = ctf = default_CTF(0, 255)
    308         self._otf = otf = default_OTF(0, 255)
    309         vp.set_color(ctf)

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in default_CTF(x1, x2)
    123                     val_range=(1.0, 1.0),
    124                     n=10,
--> 125                     mode='sqrt')
    126 
    127 

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in make_CTF(x1, x2, hue_range, sat_range, val_range, n, mode)
    101             v = val_range[0] + dval*x
    102             r, g, b, a = [sqrt(c) for c in hsva_to_rgba(h, s, v, 1.0)]
--> 103             ctf.add_rgb_point(mins+x*ds, r, g, b)
    104     elif mode == 'linear':
    105         for i in range(n+1):

c:\anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\tvtk\util\ctf.py in add_rgb_point(self, *args)
    208         ret = super(ColorTransferFunction, self).add_rgb_point(*args)
    209         self.nodes.append(args[0])
--> 210         self.nodes.sort()
    211         return ret
    212 

C:\Anaconda3\lib\site-packages\traits\trait_handlers.py in sort(self, cmp, key, reverse)
   2565     def sort ( self, cmp = None, key = None, reverse = False ):
   2566         removed = self[:]
-> 2567         list.sort( self, cmp = cmp, key = key, reverse = reverse )
   2568 
   2569         if (getattr(self, 'name_items', None) is not None and

TypeError: sort() takes at most 2 arguments (3 given)
*********************************************************************************