Cannot run nipype spm interface functions

Hi!
I’m trying to run SPM functions via nipype in a conda env notebook on a win10 machine.
I can successfully run matlab commands via MCR, which gives me output confirming that SPM12 is found.

import nipype.interfaces.matlab as matlab
mlab = matlab.MatlabCommand()
mlab.inputs.script = 'spm ver'
mlab.run()

Then i set mlab paths:

from nipype.interfaces import spm
matlab_cmd = "opt/MATLAB Runtime/v99/toolbox/spm12_r7771/spm12/run_spm12.sh opt/MATLAB/MATLAB Runtime/v99 script"
spm.SPMCommand.set_mlab_paths(matlab_cmd=matlab_cmd, use_mcr=True)

When i now call any spm function e.g.

spm.SPMCommand().version

i get

ValueError                                Traceback (most recent call last)
 File C:\Anaconda\envs\ConcSpace\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:

Full error log:

I’m assuming that there’s still something off with the correct paths, but i cannot figure out what exactly causes the problem. Anyone knows what might be wrong here?
Thanks!

1 Like

Ahoi hoi @hippocampeli,

thank you very much for your question and welcome to Neurostars, it’s great to have you here.

Given you’re using windows10 and the path you indicated above it seems that this might be the problem. The path looks very “unix”-y with / whereas one needs to use \ on windows OS (IIRC). Did you try to specify the paths in a “windows” way with \ (and maybe using absolute paths)? On a related note: are you using WSL by any chance?

HTH, cheers, Peer

Hi @PeerHerholz ,
thanks for your reply. True, the depicted paths used / but changing it to \ did not resolve the issue.
I’m also using absolute paths to indicate the locations of spm and MCR, like so:

matlab_cmd = "C:\Program Files\MATLAB\spm12_r7771\spm12\run_spm12.sh C:\Program Files\MATLAB\MATLAB Runtime\v99\ script"
spm.SPMCommand.set_mlab_paths(matlab_cmd=matlab_cmd, use_mcr=True)

The notebook i’m using here is running in an environment on drive (F:) which is different from spm / mcr locations (C:). Could this cause the issue?
Concerning WSL: it’s installed but i’m not aware of actively using it here… not sure whether this is what you meant.
Thanks!

Ahoi hoi @hippocampeli,

thx for the update, sorry it didn’t solve the issue.

Hm, windows OS is not my forte by far, sorry. Could you check if the location of the MCR ("C:\...) is accessible from your notebook (e.g. via os.listdir or so)? Maybe there’s something funky going on… . Re WSL: all good, if you’re not actively using it atm and not planning to do so in the future, we should focus on finding a solution based on your current environment.

Cheers, Peer

Hi @PeerHerholz,
from my env i can os.chdir() or os.listdir(path) into both the directories of the spm12 standalone (where run_spm12.sh is) and the MCR.
When i run
spm.SPMCommand().version
a matlab command window with the following output opens briefly:


I think it may indicate that it uses opens the installed version of Matlab (2020b) instead of the MCR, right? This also has SPM12 as a regular toolbox listed, not the standalone SPM12 version.
Hope it helps narrow it down. Glad for you help.
Best

1 Like

Ahoi hoi @hippocampeli,

thx for the update. Hm, this is puzzling…!
Could you try enforcing the SPM standalone version globally as outlined here?

HTH, cheers, Peer

Hi @hippocampeli did you solve it? Same problem same stand alone and windows 11.
Thanks