Initiating a BIDSLayout on Pybids

Hi,

I am trying out this online material on neuroimaging using python, Dartbrains (Course Overview — DartBrains) by Luke Chang from Dartmouth.

I got stuck when I tried to initiate a new BIDSLayout(Introduction to Neuroimaging Data — DartBrains).

I used this code below as instructed on my jupyter notebook, but the error message seems that python somehow does not recognize bids at all.

I’ve already installed pybids, so I don’t really understand where I missed something.
Could anyone let me know where I should look? Do I need to install other bids-related packages?
After many hours of googling and reading Neurostar posts mentioning pybids, still no luck…

from bids import BIDSLayout, BIDSValidator
# from bids.tests import get_test_data_path
import os

data_dir = '/Users/mchoi/dartbrain/data/Localizer'
layout = BIDSLayout(data_dir, derivatives = True)
layout
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [30], in <cell line: 1>()
----> 1 from bids import BIDSLayout, BIDSValidator
      2 # from bids.tests import get_test_data_path
      3 import os

ModuleNotFoundError: No module named 'bids'

Hi,

It’s possible that the kernel jupyter is running is not based on your python environment that has pybids in it. Can you try installing another package in your python environment and trying to import it in jupyter to see if it is a problem with pybids vs. a problem with your Jupyter kernel?

Best,
Steven

Hi Steven,

Thank you so much!
According to your recommendation, I tried pip list on jupyter and found that pybids were not installed (or at least not found on the anaconda/jupyter environment).
I googled this code (conda install -c aramislab pybids) to install pybids on conda and updated anaconda to the latest version :slight_smile:
And, it worked!

Thank you so much again for your explanation. Really appreciate it!