Nipype TypeError: environment can only contain strings

Dear all,
I just try to run nipype (on Windows 10). I installed Matlab, SPM, Nipype and am trying the following:

> from nipype.interfaces import spm
> print(spm.Info.path())

and get the following error:


TypeError Traceback (most recent call last)
in
1 from nipype.interfaces import spm
----> 2 print(spm.Info.path())

~\Anaconda3\lib\site-packages\nipype\interfaces\spm\base.py in path(klass, matlab_cmd, paths, use_mcr)
140 @classmethod
141 def path(klass, matlab_cmd=None, paths=None, use_mcr=None):
–> 142 klass.getinfo(matlab_cmd, paths, use_mcr)
143 return klass._path
144

~\Anaconda3\lib\site-packages\nipype\interfaces\spm\base.py in getinfo(klass, matlab_cmd, paths, use_mcr)
216 “”"
217 try:
–> 218 out = mlab.run()
219 except (IOError, RuntimeError) as e:
220 # if no Matlab at all – exception could be raised

~\Anaconda3\lib\site-packages\nipype\interfaces\base\core.py in run(self, cwd, ignore_exception, **inputs)
373 try:
374 runtime = self._pre_run_hook(runtime)
–> 375 runtime = self._run_interface(runtime)
376 runtime = self._post_run_hook(runtime)
377 outputs = self.aggregate_outputs(runtime)

~\Anaconda3\lib\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\site-packages\nipype\interfaces\base\core.py in _run_interface(self, runtime, correct_return_codes)
753 runtime.environ)
754 if self._ldd else ‘’)
–> 755 runtime = run_command(runtime, output=self.terminal_output)
756 if runtime.returncode is None or
757 runtime.returncode not in correct_return_codes:

~\Anaconda3\lib\site-packages\nipype\utils\subprocess.py in run_command(runtime, output, timeout)
113 cwd=runtime.cwd,
114 env=env,
–> 115 close_fds=(not sys.platform.startswith(‘win’)),
116 )
117

~\Anaconda3\lib\subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
773 c2pread, c2pwrite,
774 errread, errwrite,
–> 775 restore_signals, start_new_session)
776 except:
777 # Cleanup if the child failed starting.

~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1176 env,
1177 os.fspath(cwd) if cwd is not None else None,
-> 1178 startupinfo)
1179 finally:
1180 # Child is launched. Close the parent’s copy of those pipe

TypeError: environment can only contain strings

The code I posted is just representative for any kind of spm function I try to use within nipype, all with the TypeError as a result.

It seems that I have missed some basic thing, but could not find out which one.

If I have a look at my os.environment variable, all entries look like strings.

We have this very same problem on 2 different machines.

Do you have any idea?

Many thanks for any help

Ahoi hoi @kesslerr,

thanks for your post and welcome to neurostars, it’s great to have you here!

I’m not sure, but I think your error might be related to the issue raised here and here. Hence, it might be a Windows- Nipype thingy. I’m pretty sure it won’t make a difference, but you could try the following before running your code:

from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('/usr/local/MATLAB/R2014a/toolbox/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

(Of course adapting the path to your system.)

Otherwise, could you maybe use a docker or singularity container to run your analyses?

HTH, cheers, Peer

Dear @PeerHerholz,
thanks a lot for your suggestions. I tried your snippets but it still raises the same error. I am wondering if it is not a common issue, as it appeared with two of our Windows systems at the same time. Maybe some Windows User have found a workaround that does not include docker? However, I will give that a try if not !

Ahoi hoi @kesslerr,

hm, kk. Based on the issues I shared in my previous post I think it’s related to windows. I think that if someone had resolved it by now, it would most likely be posted somewhere or the issues would have been addressed. I think the majority of nipype users might not work on windows or just use docker and singularity, sorry.
I also don’t have access to a windows machine to test it, sorry.

If you use a docker or singularity image, depending on your machine and setup, you won’t loose a lot if any computational power. Plus you’ll get some more reproducibility and reusability on top for free.

HTH, cheers, Peer