0
下面的部分代碼的工作沒有任何錯誤:Nipype AttributeError的:「節點」對象沒有屬性
#fslorient forceneurological
fslorient = pe.Node(interface = fslorient.FslOrient(), name = 'fslorient')
fslorient.inputs.main_option = 'forceneurological'
然而,當我添加第二Node
用相同的腳本(fslorient
)的屬性錯誤引起:
#fslorient deleteorient
fslorient1 = pe.Node(interface = fslorient.FslOrient(), name = 'fslorient1')
fslorient1.inputs.main_option = 'deleteorient'
屬性錯誤:
Traceback (most recent call last):
File "bs_pipeline.py", line 139, in <module>
fslorient1 = pe.Node(interface = fslorient.FslOrient(), name = 'fslorient1')
AttributeError: 'Node' object has no attribute 'FslOrient'
這種合作de下面被命名爲fslorient.py
from nipype.interfaces.fsl.base import FSLCommand, FSLCommandInputSpec
from nipype.interfaces.base import TraitedSpec, File, traits
import os
class FslOrientInputSpec(FSLCommandInputSpec):
main_option = traits.Str(desc='main option', argstr='-%s', position=0, mandatory=True)
code = traits.Int(argstr='%d', desc='code for setsformcode', position=1)
in_file = File(exists=True, desc='input file', argstr='%s', position=2, mandatory=True)
class FslOrientOutputSpec(TraitedSpec):
out_file = File(desc = "out file", exists = True)
class FslOrient(FSLCommand):
_cmd = 'fslorient'
input_spec = FslOrientInputSpec
output_spec = FslOrientOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = os.path.abspath(self.inputs.in_file)
return outputs
我找不到問題。
編輯:我也用過其他的包裹,遇到同樣的錯誤!
他們的名字是不一樣的。其中一個是'fslorient',另一個是'fslorient1'。我找到了另一種方法:用不同的名稱(f1,f2等)導入'fslorient'module,但這有點令人毛骨悚然。我想以一種整潔的方式來做,並且想要了解問題出在哪裏。 –
只是不要爲變量和模塊使用相同的名稱(fslorient)。無需導入模塊兩次。也請在github上發送一個pull請求與這個新的界面,所以我們可以添加它的新版本。 –