diff --git a/nipype/interfaces/base/core.py b/nipype/interfaces/base/core.py index afafbebf84..755a33317c 100644 --- a/nipype/interfaces/base/core.py +++ b/nipype/interfaces/base/core.py @@ -26,7 +26,7 @@ from ... import config, logging, LooseVersion from ...utils.provenance import write_provenance from ...utils.misc import str2bool, rgetcwd -from ...utils.filemanip import split_filename, which, get_dependencies +from ...utils.filemanip import split_filename, which, get_dependencies, canonicalize_env from ...utils.subprocess import run_command from ...external.due import due @@ -778,7 +778,7 @@ def version_from_command(self, flag="-v", cmd=None): proc = sp.Popen( " ".join((cmd, flag)), shell=True, - env=env, + env=canonicalize_env(env), stdout=sp.PIPE, stderr=sp.PIPE, ) diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 656f4d23af..9b3741ae96 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -26,11 +26,7 @@ fmlogger = logging.getLogger("nipype.utils") -related_filetype_sets = [ - (".hdr", ".img", ".mat"), - (".nii", ".mat"), - (".BRIK", ".HEAD"), -] +related_filetype_sets = [(".hdr", ".img", ".mat"), (".nii", ".mat"), (".BRIK", ".HEAD")] def _resolve_with_filenotfound(path, **kwargs): @@ -876,7 +872,7 @@ def get_dependencies(name, environ): def canonicalize_env(env): - """Windows requires that environment be dicts with bytes as keys and values + """Windows requires that environment be dicts with str as keys and values This function converts any unicode entries for Windows only, returning the dictionary untouched in other environments. @@ -888,7 +884,7 @@ def canonicalize_env(env): Returns ------- env : dict - Windows: environment dictionary with bytes keys and values + Windows: environment dictionary with str keys and values Other: untouched input ``env`` """ if os.name != "nt": @@ -896,10 +892,10 @@ def canonicalize_env(env): out_env = {} for key, val in env.items(): - if not isinstance(key, bytes): - key = key.encode("utf-8") - if not isinstance(val, bytes): - val = val.encode("utf-8") + if not isinstance(key, str): + key = key.decode("utf-8") + if not isinstance(val, str): + val = val.decode("utf-8") out_env[key] = val return out_env