diff --git a/nipype/interfaces/base/core.py b/nipype/interfaces/base/core.py index 9345ef731a..7ba8486082 100644 --- a/nipype/interfaces/base/core.py +++ b/nipype/interfaces/base/core.py @@ -476,9 +476,9 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None): setattr(outputs, key, val) except TraitError as error: if 'an existing' in getattr(error, 'info', 'default'): - msg = "No such file or directory for output '%s' of a %s interface" % \ - (key, self.__class__.__name__) - raise FileNotFoundError(val, message=msg) + msg = "No such file or directory '%s' for output '%s' of a %s interface" % \ + (val, key, self.__class__.__name__) + raise FileNotFoundError(msg) raise error return outputs diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index c919000d34..0bfc6b3968 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -40,14 +40,16 @@ PY3 = sys.version_info[0] >= 3 - -class FileNotFoundError(OSError): # noqa - """Defines the exception for Python 2.""" - - def __init__(self, path): - """Initialize the exception.""" - super(FileNotFoundError, self).__init__( - 2, 'No such file or directory', '%s' % path) +try: + from builtins import FileNotFoundError +except ImportError: # PY27 + class FileNotFoundError(OSError): # noqa + """Defines the exception for Python 2.""" + + def __init__(self, path): + """Initialize the exception.""" + super(FileNotFoundError, self).__init__( + 2, 'No such file or directory', '%s' % path) USING_PATHLIB2 = False