nipy / nipype

Workflows and interfaces for neuroimaging packages
https://nipype.readthedocs.org/en/latest/
Other
751 stars 530 forks source link

traits.trait_errors.TraitError: Each element of the 'in_files' trait of a SmoothInputSpec instance must be a pathlike object or string representing an existing file, but a value of 'xxx’ <class 'str'> was specified. #3693

Open abcvav opened 1 month ago

abcvav commented 1 month ago

Summary

When running a script using smooth.inputs.in_files, an error occurs indicating that the in_files trait must be a pathlike object or a string representing an existing file, despite the file path being valid and existing.

Actual behavior

The script fails with the following error traceback:

Traceback (most recent call last):
  File "/Users/ab/Documents/Code/nipype_tutorial/tests/t.py", line 4, in <module>
    smooth.inputs.in_files = '/Users/ab/Documents/Code/nipype_tutorial/tests/test.nii.gz'
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 424, in validate
    value = super(MultiObject, self).validate(objekt, name, newvalue)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/traits/trait_types.py", line 2699, in validate
    return TraitListObject(self, object, name, value)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/traits/trait_list_object.py", line 582, in __init__
    super().__init__(
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/traits/trait_list_object.py", line 213, in __init__
    super().__init__(self.item_validator(item) for item in iterable)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/traits/trait_list_object.py", line 213, in <genexpr>
    super().__init__(self.item_validator(item) for item in iterable)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/traits/trait_list_object.py", line 865, in _item_validator
    return trait_validator(object, self.name, value)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 334, in validate
    self.error(objekt, name, str(value))
  File "/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/traits/base_trait_handler.py", line 74, in error
    raise TraitError(
traits.trait_errors.TraitError: Each element of the 'in_files' trait of a SmoothInputSpec instance must be a pathlike object or string representing an existing file, but a value of '/Users/ab/Documents/Code/nipype_tutorial/tests/test.nii.gz' <class 'str'> was specified.

Expected behavior

The file path '/Users/ab/Documents/Code/nipype_tutorial/tests/test.nii.gz' should be accepted as a valid path, and the smooth.inputs.in_files trait should accept it without raising an error, as the file does exist. But using an absolute path results in the same outcome.

How to replicate the behavior

run the following scripts:

from nipype.interfaces.spm import Smooth
smooth = Smooth()
smooth.inputs.in_files = '/Users/ab/Documents/Code/nipype_tutorial/tests/test.nii.gz'

Script/Workflow details

>>> from pathlib import Path
>>> Path('/Users/ab/Documents/Code/nipype_tutorial/tests/test.nii.gz').exists()
True

Platform details:

{'commit_hash': '%h',
 'commit_source': 'archive substitution',
 'networkx_version': '3.4.1',
 'nibabel_version': '5.3.1',
 'nipype_version': '1.8.6',
 'numpy_version': '2.1.2',
 'pkg_path': '/opt/homebrew/Caskroom/miniconda/base/envs/preproc/lib/python3.10/site-packages/nipype',
 'scipy_version': '1.14.1',
 'sys_executable': '/opt/homebrew/Caskroom/miniconda/base/envs/preproc/bin/python',
 'sys_platform': 'darwin',
 'sys_version': '3.10.13 | packaged by conda-forge | (main, Dec 23 2023, '
                '15:35:25) [Clang 16.0.6 ]',
 'traits_version': '6.3.2'}

Execution environment

I use miniconda, the conda version is conda 24.7.1. Nipype was installed using conda install --channel conda-forge nipype. Python version 3.10.13