Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Oct 17, 2024 · 0 comments

Comments

@abcvav
Copy link

abcvav commented Oct 17, 2024

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

  • My python environment outside container

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant