nipype icon indicating copy to clipboard operation
nipype copied to clipboard

Issue running nipype.interfaces.spm

Open nmossazg12 opened this issue 2 years ago • 2 comments
trafficstars

Hi, I am experiencing issues running nipype.interfaces.spm in my windows machine. I get "This docstring was not generated by Nipype! " error message when I run the following command. Any assistance to resolve this issue would be appreciated. Thank you!

Actual behavior

>>import nipype.interfaces.spm as spm^M
>>est = spm.EstimateContrast()

'stty' is not recognized as an internal or external command,
operable program or batch file.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~\anaconda3\envs\test\lib\site-packages\nipype\utils\spm_docs.py:49, in _strip_header(doc)
     48 try:
---> 49     index = doc.index(hdr)
     50 except ValueError as e:

ValueError: substring not found

The above exception was the direct cause of the following exception:

OSError                                   Traceback (most recent call last)
Cell In[11], line 2
      1 import nipype.interfaces.spm as spm
----> 2 est = spm.EstimateContrast()

File ~\anaconda3\envs\test\lib\site-packages\nipype\interfaces\spm\base.py:309, in SPMCommand.__init__(self, **inputs)
    308 def __init__(self, **inputs):
--> 309     super(SPMCommand, self).__init__(**inputs)
    310     self.inputs.on_trait_change(
    311         self._matlab_cmd_update, ["matlab_cmd", "mfile", "paths", "use_mcr"]
    312     )
    313     self._find_mlab_cmd_defaults()

File ~\anaconda3\envs\test\lib\site-packages\nipype\interfaces\base\core.py:197, in BaseInterface.__init__(self, from_file, resource_monitor, ignore_exception, **inputs)
    194 # Create input spec, disable any defaults that are unavailable due to
    195 # version, and then apply the inputs that were passed.
    196 self.inputs = self.input_spec()
--> 197 unavailable_traits = self._check_version_requirements(
    198     self.inputs, permissive=True
    199 )
    200 if unavailable_traits:
    201     self.inputs.trait_set(**{k: Undefined for k in unavailable_traits})

File ~\anaconda3\envs\test\lib\site-packages\nipype\interfaces\base\core.py:295, in BaseInterface._check_version_requirements(self, trait_object, permissive)
    292 check = dict(min_ver=lambda t: t is not None)
    293 names = trait_object.trait_names(**check)
--> 295 if names and self.version:
    296     version = LooseVersion(str(self.version))
    297     for name in names:

File ~\anaconda3\envs\test\lib\site-packages\nipype\interfaces\spm\base.py:357, in SPMCommand.version(self)
    355 @property
    356 def version(self):
--> 357     info_dict = Info.getinfo(
    358         matlab_cmd=self.inputs.matlab_cmd,
    359         paths=self.inputs.paths,
    360         use_mcr=self.inputs.use_mcr,
    361     )
    362     if info_dict:
    363         return "%s.%s" % (info_dict["name"].split("SPM")[-1], info_dict["release"])

File ~\anaconda3\envs\test\lib\site-packages\nipype\interfaces\spm\base.py:238, in Info.getinfo(klass, matlab_cmd, paths, use_mcr)
    235     klass._paths = paths
    236     return None
--> 238 out = sd._strip_header(out.runtime.stdout)
    239 out_dict = {}
    240 for part in out.split("|"):

File ~\anaconda3\envs\test\lib\site-packages\nipype\utils\spm_docs.py:51, in _strip_header(doc)
     49     index = doc.index(hdr)
     50 except ValueError as e:
---> 51     raise IOError("This docstring was not generated by Nipype!\n") from e
     53 index += len(hdr)
     54 index += 1

OSError: This docstring was not generated by Nipype!

Execution environment

python version 3.9.16 nipype version 1.8.4

nmossazg12 avatar Jun 09 '23 20:06 nmossazg12

Nipype is not supported on Windows. You may be able to use the Windows Subsystem for Linux to get it working, however. I don't know, though.

effigies avatar Jun 09 '23 20:06 effigies

Thank you @effigies.

nmossazg12 avatar Jun 09 '23 20:06 nmossazg12

Hi @effigies, I am having a similar issue and is unrelated to the OS used since I am running it in Linux.

Loading SPM Interface using nipype release 1.6,

In [1]: import nipype; nipype.__version__
Out[1]: '1.6.1'

In [2]: import nipype.interfaces.spm as spm
240610-16:54:36,61 nipype.utils WARNING:
         A newer version (1.8.4) of nipy/nipype is available. You are using 1.6.1

In [3]: spm.SPMCommand.set_mlab_paths(matlab_cmd='spm12 script', use_mcr=True)

In [4]: spm.Realign()
Out[4]: <nipype.interfaces.spm.preprocess.Realign at 0x7f1f84c03908>

Loading SPM Interface using nipype release 1.7 or above,

In [1]: import nipype; nipype.__version__
Out[1]: '1.8.6'

In [2]: import nipype.interfaces.spm as spm

In [3]: spm.SPMCommand.set_mlab_paths(matlab_cmd='spm12 script', use_mcr=True)

In [4]: spm.Realign()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/p3/lib/python3.7/site-packages/nipype/utils/spm_docs.py in _strip_header(doc)
     48     try:
---> 49         index = doc.index(hdr)
     50     except ValueError as e:

ValueError: substring not found

The above exception was the direct cause of the following exception:

OSError                                   Traceback (most recent call last)
<ipython-input-3-9ebc2828a699> in <module>
----> 1 spm.Realign()

/tmp/p3/lib/python3.7/site-packages/nipype/interfaces/spm/base.py in __init__(self, **inputs)
    307
    308     def __init__(self, **inputs):
--> 309         super(SPMCommand, self).__init__(**inputs)
    310         self.inputs.on_trait_change(
    311             self._matlab_cmd_update, ["matlab_cmd", "mfile", "paths", "use_mcr"]

/tmp/p3/lib/python3.7/site-packages/nipype/interfaces/base/core.py in __init__(self, from_file, resource_monitor, ignore_exception, **inputs)
    196         self.inputs = self.input_spec()
    197         unavailable_traits = self._check_version_requirements(
--> 198             self.inputs, permissive=True
    199         )
    200         if unavailable_traits:

/tmp/p3/lib/python3.7/site-packages/nipype/interfaces/base/core.py in _check_version_requirements(self, trait_object, permissive)
    293         names = trait_object.trait_names(**check)
    294
--> 295         if names and self.version:
    296             version = LooseVersion(str(self.version))
    297             for name in names:

/tmp/p3/lib/python3.7/site-packages/nipype/interfaces/spm/base.py in version(self)
    358             matlab_cmd=self.inputs.matlab_cmd,
    359             paths=self.inputs.paths,
--> 360             use_mcr=self.inputs.use_mcr,
    361         )
    362         if info_dict:

/tmp/p3/lib/python3.7/site-packages/nipype/interfaces/spm/base.py in getinfo(klass, matlab_cmd, paths, use_mcr)
    236             return None
    237
--> 238         out = sd._strip_header(out.runtime.stdout)
    239         out_dict = {}
    240         for part in out.split("|"):

/tmp/p3/lib/python3.7/site-packages/nipype/utils/spm_docs.py in _strip_header(doc)
     49         index = doc.index(hdr)
     50     except ValueError as e:
---> 51         raise IOError("This docstring was not generated by Nipype!\n") from e
     52
     53     index += len(hdr)

OSError: This docstring was not generated by Nipype!

Any ideas of what's going on?

jhuguetn avatar Jun 10 '24 15:06 jhuguetn

No. If you're using IPython, you can set the %pdb magic, and then move up and down the trace to see what the values are.

For example, in getinfo(), what is the value of out.runtime.stdout?

effigies avatar Jun 10 '24 15:06 effigies

Well, that's embarrassing but it works fine now, no matter what I try but I am unable to reproduce it:

(venv_p3) jordi@dev-barcelonabrainimaging:~> ipython
Python 3.7.2 (default, Mar 26 2019, 12:41:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import nipype.interfaces.spm as spm

In [2]: import nipype; nipype.__version__
Out[2]: '1.8.6'

In [3]: spm.SPMCommand.set_mlab_paths(matlab_cmd='spm12 script', use_mcr=True)

In [4]: spm.Realign()
Out[4]: <nipype.interfaces.spm.preprocess.Realign at 0x7f55ca6aaa58>

Forget it then. Thanks for your prompt reply!

jhuguetn avatar Jun 10 '24 16:06 jhuguetn