Repository: nipy/nipype

Issue:
spm.SPMCommand.set_mlab_paths doesn't change spm version
### Summary
It looks like changing paths using `spm.SPMCommand.set_mlab_paths` doesn't affect some of the checks: e.g. `spm.Info.name()`, `spm.SPMCommand().version` or `spm.base.no_spm()`.

Some checks (e.g. `spm.SPMCommand().version` ) stopped working properly between 0.13.1 and 0.14

This problem is related to #2436

Matlab command cannot be found
### Summary
Hello, I'm new to nipype and I am following preprocessing tutorial in the NypypeBeginnersGuide, and I cannot seem to run the workflow or write a graph.
The workflow unzips the file, but crashes at slice timing.
The crash file created states that matlab command cannot be found, but I have matlab 2016b and SPM12 installed. 
Also, the error tells that 'No command 'dot' found' when I try to write a graph. 

When testing nipype with nipype.test(), a fauilure occurs in test_Commandline().
I've deleted and reinstalled nipype twice, but this problem occurred both times.

How can I resolve these issues?

### Actual behavior
When trying to write a graph,
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-9-026c77eb0f4a> in <module>()
      1 # 7. run workflow
----> 2 pp.write_graph(graph2use='flat')

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py in write_graph(self, dotfilename, graph2use, format, simple_form)
    448                 dotfilename=dotfilename,
    449                 format=format,
--> 450                 simple_form=simple_form)
    451 
    452         logger.info(

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/utils.py in export_graph(graph_in, base_dir, show, use_execgraph, show_connectinfo, dotfilename, format, simple_form)
   1285 
   1286     # Convert .dot if format != 'dot'
-> 1287     outfname, res = _run_dot(out_dot, format_ext=format)
   1288     if res is not None and res.runtime.returncode:
   1289         logger.warning('dot2png: %s', res.runtime.stderr)

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/utils.py in _run_dot(dotfilename, format_ext)
   1328     cmd = 'dot -T{} -o"{}" "{}"'.format(format_ext, formatted_dot, dotfilename)
   1329     res = CommandLine(cmd, terminal_output='allatonce',
-> 1330                       resource_monitor=False).run()
   1331     return formatted_dot, res
   1332 

~/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py in run(self, cwd, **inputs)
    513 
    514         try:
--> 515             runtime = self._run_interface(runtime)
    516             outputs = self.aggregate_outputs(runtime)
    517         except Exception as e:

~/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py in _run_interface(self, runtime, correct_return_codes)
   1011                 'No command "%s" found on host %s. Please check that the '
   1012                 'corresponding package is installed.' % (executable_name,
-> 1013                                                          runtime.hostname))
   1014 
   1015         runtime.command_path = cmd_path

OSError: No command "dot" found on host Juyoungs-MacBook-Pro.local. Please check that the corresponding package is installed.

When trying to run the workflow,

180212-11:06:51,706 workflow INFO:
	 Workflow preprocessing settings: ['check', 'execution', 'logging', 'monitoring']
180212-11:06:51,759 workflow INFO:
	 Running serially.
180212-11:06:51,763 workflow INFO:
	 [Node] Setting-up "preprocessing.selectfiles" in "/Users/juyoungkim/D_drive/spm_study_1702/spm_practice/nipype_tutorial/wd_preprocessing/preprocessing/_session_id_run001_subject_id_sub002/selectfiles".
180212-11:06:51,785 workflow INFO:
	 [Node] Running "selectfiles" ("nipype.interfaces.io.SelectFiles")
180212-11:06:51,823 workflow INFO:
	 [Node] Finished "preprocessing.selectfiles".
180212-11:06:51,825 workflow INFO:
	 [Node] Setting-up "preprocessing.gunzip" in "/Users/juyoungkim/D_drive/spm_study_1702/spm_practice/nipype_tutorial/wd_preprocessing/preprocessing/_session_id_run001_subject_id_sub002/gunzip".
180212-11:06:51,834 workflow INFO:
	 [Node] Cached "preprocessing.gunzip" - collecting precomputed outputs
180212-11:06:51,841 workflow INFO:
	 [Node] "preprocessing.gunzip" found cached.
180212-11:06:51,845 workflow INFO:
	 [Node] Setting-up "preprocessing.slice_timing" in "/Users/juyoungkim/D_drive/spm_study_1702/spm_practice/nipype_tutorial/wd_preprocessing/preprocessing/_session_id_run001_subject_id_sub002/slice_timing".
180212-11:06:51,898 workflow INFO:
	 [Node] Running "slice_timing" ("nipype.interfaces.spm.preprocess.SliceTiming")
180212-11:06:51,923 workflow WARNING:
	 [Node] Error on "preprocessing.slice_timing" (/Users/juyoungkim/D_drive/spm_study_1702/spm_practice/nipype_tutorial/wd_preprocessing/preprocessing/_session_id_run001_subject_id_sub002/slice_timing)
180212-11:06:51,929 workflow ERROR:
	 Node slice_timing.a1 failed to run on host Juyoungs-MacBook-Pro.local.
180212-11:06:51,972 workflow ERROR:
	 Saving crash info to /Users/juyoungkim/D_drive/spm_study_1702/spm_practice/nipype_tutorial/crash-20180212-110651-juyoungkim-slice_timing.a1-bffe58c0-53dd-4946-abe8-a60895ad07c9.pklz
Traceback (most recent call last):
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py", line 44, in run
    node.run(updatehash=updatehash)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 487, in run
    result = self._run_interface(execute=True)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 571, in _run_interface
    return self._run_command(execute)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 650, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 515, in run
    runtime = self._run_interface(runtime)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/spm/base.py", line 359, in _run_interface
    results = self.mlab.run()
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 515, in run
    runtime = self._run_interface(runtime)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/matlab.py", line 162, in _run_interface
    runtime = super(MatlabCommand, self)._run_interface(runtime)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 1013, in _run_interface
    runtime.hostname))
OSError: No command "matlab" found on host Juyoungs-MacBook-Pro.local. Please check that the corresponding package is installed.

Crash file states,
1_subject_id_sub001/slice_timing


Node inputs:

ignore_exception = False
in_files = ['/Users/juyoungkim/D_drive/spm_study_1702/spm_practice/nipype_tutorial/wd_preprocessing/preprocessing/_session_id_run001_subj
ect_id_sub001/slice_timing/run001.nii']
matlab_cmd = <undefined>
mfile = True
num_slices = 40
out_prefix = a
paths = <undefined>
ref_slice = 2
slice_order = [1.0, 3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0, 17.0, 19.0, 21.0, 23.0, 25.0, 27.0, 29.0, 31.0, 33.0, 35.0, 37.0, 39.0, 2.0, 4.
0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0, 34.0, 36.0, 38.0, 40.0]
time_acquisition = 1.95
time_repetition = 2.0
use_mcr = <undefined>
use_v8struct = True



Traceback:
Traceback (most recent call last):
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py", line 44, in run
    node.run(updatehash=updatehash)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 487, in run
    result = self._run_interface(execute=True)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 571, in _run_interface
    return self._run_command(execute)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 650, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 515, in run
    runtime = self._run_interface(runtime)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/spm/base.py", line 359, in _run_interface
    results = self.mlab.run()
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 515, in run
    runtime = self._run_interface(runtime)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/matlab.py", line 162, in _run_interface
    runtime = super(MatlabCommand, self)._run_interface(runtime)
  File "/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 1013, in _run_interface
    runtime.hostname))
OSError: No command "matlab" found on host Juyoungs-MacBook-Pro.local. Please check that the corresponding package is installed.

### Expected behavior
Write a graph and run the preprocessing workflow.

### How to replicate the behavior

### Script/Workflow details

Please put URL to code or code here (if not too long).

### Platform details:

Please paste the output of: `python -c "import nipype; print(nipype.get_info()); print(nipype.__version__)"`

### Execution environment
I'm running on Jupyter notebook, on Mac os, and have Nipype 1.0, MATLAB2016b and SPM12 installed.

Choose one
- Container [Tag: ???]
- My python environment inside container [Base Tag: ???]
- My python environment outside container



Discussion:
@djarecka - if `SPMCommand` paths are set, they should influence `Info` as well. i think that is all that is broken. once `Info` is updated, the others should work automatically.
@djarecka - i just ran this in the nipype test container (`nipype/nipype:py36`) without invoking the entrypoint, and with some debug prints.

```python
>>> import nipype.interfaces.spm as spm
>>> spm.Info.version()
/opt/mcr/v92/toolbox/matlab
>>> spm.Info.version(matlab_cmd='/opt/spm12/run_spm12.sh /opt/mcr/v92/ script')
/opt/spm12/run_spm12.sh /opt/mcr/v92/ script
stty: 'standard input': Inappropriate ioctl for device
path:/opt/spm12/spm12_mcr/spm/spm12|name:SPM12|release:7169
'7169'
spm.SPMCommand().version
'12.7169'
```
also on os x:

```python
In [1]: import nipype.interfaces.spm as spm
180219-15:35:18,460 duecredit ERROR:
	 Failed to import duecredit due to No module named 'duecredit'

In [2]: spm.SPMCommand().version
matlab -nodesktop -nosplash

In [3]: spm.Info.version
Out[3]: <bound method Info.version of <class 'nipype.interfaces.spm.base.Info'>>

In [4]: spm.Info.version()
matlab -nodesktop -nosplash

In [5]: spm.SPMCommand.set_mlab_paths(paths='/software/matlab/spm12')

In [6]: spm.SPMCommand().version
matlab -nodesktop -nosplash
path:/software/matlab/spm12|name:SPM12|release:6225
Out[6]: '12.6225'

In [7]: spm.Info.version()
Out[7]: '6225'
```
so everything seems like it's working the way it is supposed to.
let me take that back - i did make one fix :)

will push in a second.
@jykim24 - you mentioned several issues here,  will try to address at least some of them:

* re. `dot`: `write_graph` function used in Nipypes requires a software called `graphviz`, I know there are some issues on OSX, as far as I remember `brew install graphviz` helped in my case. You can always check if you have `dot` in your terminal `dot -V`. FYI: you don't need `dot` to run the nipype workflow.

* re spm: can you check what is the output `python -c "from nipype.interfaces import spm; print(spm.Info.name())"`?

* re failing test: can you please share what is the failure message that you get from `test_Commandline()`

* general comment: I'm not sure if NipypeBeginnersGuide has been updated recently (@miykael will know more) and don't know which example you're trying to run, but you can also check [nipype tutorial](https://github.com/miykael/nipype_tutorial) that has been recently updated and tested.
@djarecka 
Thanks so much for the prompt reply!
I have been following the same tutorial on the link, using the flanker task dataset.

1. dot: I didn't know dot is not mandatory to run the workflow. I haven't tried the command yet, but I will. Thanks for the tip!

2. spm: the output of the code line says 'None', but I have SPM12 installed, and it's added to path in my MATLAB. 

3. test failure message:

=================================================================== FAILURES ====================================================================
____________________________________________________________ test_CommandLine_output ____________________________________________________________

tmpdir = local('/private/var/folders/nf/6my3rs5d7kx9rvdr2jg72wsr0000gn/T/pytest-of-juyoungkim/pytest-26/test_CommandLine_output0')

    def test_CommandLine_output(tmpdir):
        # Create one file
        tmpdir.chdir()
        file = tmpdir.join('foo.txt')
        file.write('123456\n')
        name = os.path.basename(file.strpath)
    
        ci = nib.CommandLine(command='ls -l')
        ci.terminal_output = 'allatonce'
        res = ci.run()
        assert res.runtime.merged == ''
        assert name in res.runtime.stdout
    
        # Check stdout is written
        ci = nib.CommandLine(command='ls -l')
        ci.terminal_output = 'file_stdout'
        res = ci.run()
        assert os.path.isfile('stdout.nipype')
        assert name in res.runtime.stdout
        tmpdir.join('stdout.nipype').remove(ignore_errors=True)
    
        # Check stderr is written
        ci = nib.CommandLine(command='ls -l')
        ci.terminal_output = 'file_stderr'
        res = ci.run()
        assert os.path.isfile('stderr.nipype')
        tmpdir.join('stderr.nipype').remove(ignore_errors=True)
    
        # Check outputs are thrown away
        ci = nib.CommandLine(command='ls -l')
        ci.terminal_output = 'none'
        res = ci.run()
        assert res.runtime.stdout == '' and \
            res.runtime.stderr == '' and \
            res.runtime.merged == ''
    
        # Check that new interfaces are set to default 'stream'
        ci = nib.CommandLine(command='ls -l')
        res = ci.run()
>       assert ci.terminal_output == 'stream'
E       AssertionError: assert 'file' == 'stream'
E         - file
E         + stream

/Users/juyoungkim/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/tests/test_core.py:441: AssertionError
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================== 1 failed, 635 passed, 5 skipped in 29.46 seconds ================================================

re 2: let's try to set the path manually, you can check `python -c "from nipype.interfaces import spm; spm.SPMCommand.set_mlab_paths(paths='/your/path/to/spm'); print(spm.Info.name())"`

If this helps, you can add `spm.SPMCommand.set_mlab_paths` at the beginning of the script to help nipype to find your spm.
I've tried, but  'print(spm.Info.name())' still gives 'None'.
SPM runs just fine on Matlab, though.

@djarecka 
I've also tried to add path to .bash_profile but it didn't work either.

from nipype.interfaces import spm
from nipype import config, logging
config.enable_debug_mode()
logging.update_logging(config)
spm.SPMCommand.set_mlab_paths(paths='/Applications/MATLAB_R2016b/toolbox/spm12/')
print(spm.Info.name())
print(spm.SPMCommand().version)

above lines give me the following messages:

180212-19:58:09,71 interface DEBUG:
	 nodesktop_True
180212-19:58:09,75 interface DEBUG:
	 nosplash_True
180212-19:58:09,89 interface DEBUG:
	 single_comp_thread_True
180212-19:58:09,95 interface DEBUG:
	 No command "matlab" found on host Juyoungs-MacBook-Pro.local. Please check that the corresponding package is installed.
None
180212-19:58:09,104 interface DEBUG:
	 nodesktop_True
180212-19:58:09,117 interface DEBUG:
	 nosplash_True
180212-19:58:09,122 interface DEBUG:
	 single_comp_thread_True
180212-19:58:09,133 interface DEBUG:
	 No command "matlab" found on host Juyoungs-MacBook-Pro.local. Please check that the corresponding package is installed.
None

It seems I can't run matlab from nipype, and that's causing the problems.
Is there something I can try?

Thanks in advance!

can you try `spm.SPMCommand.set_mlab_paths(paths='/your/path/to/spm', matlab_cmd='/path/to/matlab -nodesktop -nosplash')` instead of  `spm.SPMCommand.set_mlab_paths(paths='/your/path/to/spm')`
@jykim24 - can ask you to create a separate issue for the failing test? It doesn't seem to be related to your problems with spm and the tutorial. I personally never seen it and can't reproduce it, other people might have better ideas when they see it.
@djarecka 

Sure, I will create a separate issue for test failure.
For your suggested solution, I've tried running the following code.

from nipype.interfaces import matlab
from nipype.interfaces import spm
spm.SPMCommand.set_mlab_paths(paths='/Applications/MATLAB_R2016b.app/toolbox/spm12/')
matlab_cmd='/Applications/MATLAB_R2016b -nodesktop -nosplash'
print(spm.Info.name())

When I run the code, I still get 'None' & 'None', and when I try to run a workflow, I get the following error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-50-ee385f7c820b> in <module>()
----> 1 pp.run()

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py in run(self, plugin, plugin_args, updatehash)
    600         if str2bool(self.config['execution']['create_report']):
    601             self._write_report_info(self.base_dir, self.name, execgraph)
--> 602         runner.run(execgraph, updatehash=updatehash, config=self.config)
    603         datestr = datetime.utcnow().strftime('%Y%m%dT%H%M%S')
    604         if str2bool(self.config['execution']['write_provenance']):

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py in run(self, graph, config, updatehash)
     42                 if self._status_callback:
     43                     self._status_callback(node, 'start')
---> 44                 node.run(updatehash=updatehash)
     45                 if self._status_callback:
     46                     self._status_callback(node, 'end')

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py in run(self, updatehash)
    485 
    486         try:
--> 487             result = self._run_interface(execute=True)
    488         except Exception:
    489             logger.warning('[Node] Error on "%s" (%s)', self.fullname, outdir)

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py in _run_interface(self, execute, updatehash)
    569             self._update_hash()
    570             return self._load_results()
--> 571         return self._run_command(execute)
    572 
    573     def _load_results(self):

~/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py in _run_command(self, execute, copyfiles)
    648         logger.info(message)
    649         try:
--> 650             result = self._interface.run(cwd=outdir)
    651         except Exception as msg:
    652             result.runtime.stderr = '%s\n\n%s'.format(

~/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py in run(self, cwd, **inputs)
    513 
    514         try:
--> 515             runtime = self._run_interface(runtime)
    516             outputs = self.aggregate_outputs(runtime)
    517         except Exception as e:

~/anaconda3/lib/python3.6/site-packages/nipype/interfaces/spm/base.py in _run_interface(self, runtime)
    357         self.mlab.inputs.script = self._make_matlab_command(
    358             deepcopy(self._parse_inputs()))
--> 359         results = self.mlab.run()
    360         runtime.returncode = results.runtime.returncode
    361         if self.mlab.inputs.uses_mcr:

~/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py in run(self, cwd, **inputs)
    513 
    514         try:
--> 515             runtime = self._run_interface(runtime)
    516             outputs = self.aggregate_outputs(runtime)
    517         except Exception as e:

~/anaconda3/lib/python3.6/site-packages/nipype/interfaces/matlab.py in _run_interface(self, runtime)
    160     def _run_interface(self, runtime):
    161         self.terminal_output = 'allatonce'
--> 162         runtime = super(MatlabCommand, self)._run_interface(runtime)
    163         try:
    164             # Matlab can leave the terminal in a barbbled state

~/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py in _run_interface(self, runtime, correct_return_codes)
   1011                 'No command "%s" found on host %s. Please check that the '
   1012                 'corresponding package is installed.' % (executable_name,
-> 1013                                                          runtime.hostname))
   1014 
   1015         runtime.command_path = cmd_path

OSError: No command "matlab" found on host Juyoungs-MacBook-Pro.local. Please check that the corresponding package is installed.


@jykim24 - if you copied-pasted the exact code, there is a typo. `matlab_cmd` should be an argument to `set_mlab_paths`, so try `spm.SPMCommand.set_mlab_paths(paths='/Applications/MATLAB_R2016b.app/toolbox/spm12/',
matlab_cmd='/Applications/MATLAB_R2016b -nodesktop -nosplash')`
@djarecka 

Okay, I've tried the the code as below, but this still gives me 'none' as output.

spm.SPMCommand.set_mlab_paths(paths='/Applications/MATLAB_R2016b.app/toolbox/spm12/', matlab_cmd='/Applications/MATLAB_R2016b -nodesktop -nosplash')
print(spm.Info.name())


@jykim24 - it seems you are on os x. your matlab command is likely to be:

`/Applications/MATLAB_R2016b.app/bin/matlab -nodesktop -nosplash`
thanks @satra, it was my mistake that I wrote that this should be path to matlab.
@satra @djarecka 
Thanks, but even when I change matlab_cmd as you suggested, spm.Info.name() still gives me 'none'.
@jykim24 - can you open a terminal and type:

`which matlab`

if that returns empty, then type:

`find /Applications/MATLAB_R2016b -name "matlab"`

let's first make sure we can find matlab via the terminal.
@satra 
'which matlab' returns nothing, and the second line returns 'No such file or directory'.
I think for a newer versions of Matlab you have to modify a directory name to `/Applications/MATLAB_R2016.app`, so try `find /Applications/MATLAB_R2016b.app -name "matlab"`

If this gives 'No such file or directory', you can always check the content of `ls -l /Application` to see what is the correct name of your matlab directory
@djarecka @satra 
find /Applications/MATLAB_R2016b.app -name "matlab"  in terminal returns the following list.

/Applications/MATLAB_R2016b.app/appdata/components/matlab
/Applications/MATLAB_R2016b.app/appdata/files/matlab
/Applications/MATLAB_R2016b.app/bin/matlab
/Applications/MATLAB_R2016b.app/examples/matlab
/Applications/MATLAB_R2016b.app/extern/engines/python/dist/matlab
/Applications/MATLAB_R2016b.app/help/examples/matlab
/Applications/MATLAB_R2016b.app/help/matlab
/Applications/MATLAB_R2016b.app/java/jar/toolbox/matlab
/Applications/MATLAB_R2016b.app/mcr/toolbox/matlab
/Applications/MATLAB_R2016b.app/resources/coreui/matlab
/Applications/MATLAB_R2016b.app/sys/g11n/ja_JP/matlab
/Applications/MATLAB_R2016b.app/sys/g11n/ko_KR/matlab
/Applications/MATLAB_R2016b.app/sys/g11n/zh_CN/matlab
/Applications/MATLAB_R2016b.app/toolbox/compiler_sdk/mps_clients/python/dist/matlab
/Applications/MATLAB_R2016b.app/toolbox/compiler_sdk/pysdk_py/mlarray_dist/matlab
/Applications/MATLAB_R2016b.app/toolbox/eml/lib/matlab
/Applications/MATLAB_R2016b.app/toolbox/matlab
/Applications/MATLAB_R2016b.app/toolbox/matlab/datatools/inspector/matlab
/Applications/MATLAB_R2016b.app/toolbox/nnet/nnresource/nnet6/icon/general/matlab
/Applications/MATLAB_R2016b.app/toolbox/shared/dsp/vision/matlab

ok, so you do have `/Applications/MATLAB_R2016b.app/bin/matlab`. I'm not sure why your workflow doesn't work, but let's try a few from commands from terminal (I know I already asked for some, but not sure if you run in basic python interpreter or jupyter notebook):

* just to check if matlab command doesn't give any errors, in terminal: `/Applications/MATLAB_R2016b.app/bin/matlab -nodesktop -nosplash`

* just to check that SPM path is ok, try to check content `ls -l /Applications/MATLAB_R2016b.app/toolbox/spm12/`. You should see hundreds of matlab scripts,`*.m`, you don't have to copy the output, just check if it's ok.

* if output from both commands look ok, try again setting paths and command in nipype.  please type in terminal (not in jupyter notebook):
`python -c "from nipype.interfaces import spm; spm.SPMCommand.set_mlab_paths(paths='/Applications/MATLAB_R2016b.app/toolbox/spm12/', matlab_cmd='/Applications/MATLAB_R2016b.app/bin/matlab -nodesktop -nosplash'); print(spm.Info.name()); print(spm.SPMCommand().version)"`

@djarecka 

Outputs of first and second commands look okay, but when I copy & paste the 3rd command on terminal, it returns 'Error: The expression to the left of the equals sign is not a valid target for an assignment.' 
@jykim24 - could you have some problems with copying the command? not sure what was wrong. If still doesn't work, you can go to python interpreter `python` and run following commands:
`from nipype.interfaces import spm`
`spm.SPMCommand.set_mlab_paths(paths='/Applications/MATLAB_R2016b.app/toolbox/spm12/', matlab_cmd='/Applications/MATLAB_R2016b.app/bin/matlab -nodesktop -nosplash')`
`print(spm.Info.name())`
`print(spm.SPMCommand().version)`


@djarecka - this `print(spm.Info.name())` won't work properly because the paths and command set in `SPMCommand` does not carry over to `Info`
@satra yes, I've been just checking this today and I also noticed that my `spm.Info().name` doesn't change after setting... Trying to check when this stopped working. Please let me know if you know when this happened.
ok, so `spm.SPMCommand().version` stopped working correctly between 0.13.1 and 0.14.

I will open another issue with more specific description

Resolving patch:
diff --git a/nipype/interfaces/spm/base.py b/nipype/interfaces/spm/base.py
--- a/nipype/interfaces/spm/base.py
+++ b/nipype/interfaces/spm/base.py
@@ -126,28 +126,30 @@ def scans_for_fnames(fnames, keep4d=False, separate_sessions=False):
 
 class Info(PackageInfo):
     """Handles SPM version information
+
+    If you use `SPMCommand.set_mlab_paths` to set alternate entries for
+    matlab_cmd, paths, and use_mcr, then you will need to use the same entries
+    to any call in the Info class to maintain memoization. Otherwise, it will
+    default to the parameters in the `getinfo` function below.
     """
     _path = None
     _name = None
+    _command = None
+    _paths = None
+    _version = None
 
     @classmethod
     def path(klass, matlab_cmd=None, paths=None, use_mcr=None):
-        if klass._path:
-            return klass._path
         klass.getinfo(matlab_cmd, paths, use_mcr)
         return klass._path
 
     @classmethod
     def version(klass, matlab_cmd=None, paths=None, use_mcr=None):
-        if klass._version:
-            return klass._version
         klass.getinfo(matlab_cmd, paths, use_mcr)
         return klass._version
 
     @classmethod
     def name(klass, matlab_cmd=None, paths=None, use_mcr=None):
-        if klass._name:
-            return klass._name
         klass.getinfo(matlab_cmd, paths, use_mcr)
         return klass._name
 
@@ -169,7 +171,10 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
             If none of the above was successful, the fallback value of
             'matlab -nodesktop -nosplash' will be used.
         paths : str
+            Add paths to matlab session
         use_mcr : bool
+            Whether to use the MATLAB Common Runtime. In this case, the
+            matlab_cmd is expected to be a valid MCR call.
 
         Returns
         -------
@@ -178,17 +183,19 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
             returns None of path not found
         """
 
-        if klass._name and klass._path and klass._version:
+        use_mcr = use_mcr or 'FORCE_SPMMCR' in os.environ
+        matlab_cmd = matlab_cmd or ((use_mcr and os.getenv('SPMMCRCMD'))
+                      or os.getenv('MATLABCMD', 'matlab -nodesktop -nosplash'))
+
+        if klass._name and klass._path and klass._version and \
+                klass._command == matlab_cmd and klass._paths == paths:
+
             return {
                 'name': klass._name,
                 'path': klass._path,
                 'release': klass._version
             }
-
-        use_mcr = use_mcr or 'FORCE_SPMMCR' in os.environ
-        matlab_cmd = ((use_mcr and os.getenv('SPMMCRCMD'))
-                      or os.getenv('MATLABCMD', 'matlab -nodesktop -nosplash'))
-
+        logger.debug('matlab command or path has changed. recomputing version.')
         mlab = MatlabCommand(matlab_cmd=matlab_cmd, resource_monitor=False)
         mlab.inputs.mfile = False
         if paths:
@@ -214,6 +221,11 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
             # if no Matlab at all -- exception could be raised
             # No Matlab -- no spm
             logger.debug('%s', e)
+            klass._version = None
+            klass._path = None
+            klass._name = None
+            klass._command = matlab_cmd
+            klass._paths = paths
             return None
 
         out = sd._strip_header(out.runtime.stdout)
@@ -225,6 +237,8 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
         klass._version = out_dict['release']
         klass._path = out_dict['path']
         klass._name = out_dict['name']
+        klass._command = matlab_cmd
+        klass._paths = paths
         return out_dict
 
 
@@ -296,6 +310,10 @@ def set_mlab_paths(cls, matlab_cmd=None, paths=None, use_mcr=None):
         cls._matlab_cmd = matlab_cmd
         cls._paths = paths
         cls._use_mcr = use_mcr
+        info_dict = Info.getinfo(
+            matlab_cmd=matlab_cmd,
+            paths=paths,
+            use_mcr=use_mcr)
 
     def _find_mlab_cmd_defaults(self):
         # check if the user has set environment variables to enforce


Test patch: