Issues with BIDSLayout in Nipype


I try to use nipype BIDSDataGrabber to iterate through subject’s files.
When I try to use it I get an error.
The code I try to run is:

from import BIDSDataGrabber
bg_all = pe.Node(BIDSDataGrabber(), name=‘bids-grabber’)
bg_all.inputs.base_dir = data_dir
bg_all.inputs.output_query = {‘bolds’: dict(type=‘bold’)}
bg_all.iterables = (‘subject’, layout.get_subjects()[:2])

The error I receive is:

190806-09:49:16,733 nipype.workflow INFO:
[Node] Setting-up “bids-grabber” in “/tmp/tmp0eqr4eua/bids-grabber”.
190806-09:49:16,740 nipype.workflow INFO:
[Node] Running “bids-grabber” (“”)
190806-09:49:16,747 nipype.workflow WARNING:
[Node] Error on “bids-grabber” (/tmp/tmp0eqr4eua/bids-grabber)

Traceback (most recent call last):

File “”, line 1, in

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/”, line 472, in run
result = self._run_interface(execute=True)

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/”, line 563, in _run_interface
return self._run_command(execute)

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/”, line 643, in _run_command
result =

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/”, line 377, in run
outputs = self.aggregate_outputs(runtime)

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/”, line 455, in aggregate_outputs
predicted_outputs = self._list_outputs()

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/interfaces/”, line 2831, in _list_outputs
from bids import BIDSLayout

ImportError: cannot import name ‘BIDSLayout’

If I use a different pybids import there is no issue at all.

from bids.grabbids import BIDSLayout
layout = BIDSLayout(data_dir)

Any idea what is happening?


Hi @orduek,

It looks like this might be an issue of different pybids versions. Could you confirm that you can execute from bids import BIDSLayout in a python console ? Could you also send your bids version (accessible with bids.__version__) ?



1 Like

The import works ok.
Version is 0.9.2



Ahoi hoi @orduek & @emdupre,

I think @emdupre is right, it looks like you’re using different python environments, as pybids.grabbids is not a thing anymore since pybids version 0.7 (please check here for the corresponding API change). So, it appears that your nipype script runs in a different environment than whatever python console you tried. Could you maybe check that via e.g., running which python in your shell or have a look at the project interpreter of whatever IDE you’re using?

HTH, cheers, Peer

1 Like

Indeed you were right - I’ve updated the pybids version.
But now I face a new problem - BIDSLayout finds nothing in my folder, although it was built by fmriPrep.


Ahoi hoi @orduek,

ok, cool, we’re getting there.
So the workflow runs, but returns nothing or does it give you an error?
Could you try in your shell again and/or try the approach mentioned here?

HTH, cheers, Peer


I think it works.
For some reason, I can’t find the option to read only specific modalities (‘func’).
When I run layout.modalities() I get an empty list