Nipype can't find FSL executable file

Hello, I’m using FSL with nipype and it is unable to find the executable file ‘feat_model’ from fsl, even though it’s definitely in my fsl installation - any suggestions? I must be missing a simple command to help nipype find it…

Code:

import pandas as pd
import glob
from nipype.interfaces.base import Bunch
import nipype.interfaces.fsl as fsl  
import nipype.pipeline.engine as pe 
import nipype.algorithms.modelgen as model  
import os  

data_path = '/path/to/my/processed/data/'; 
os.chdir(data_path)

fsl.FSLCommand.set_default_output_type('NIFTI_GZ')

#Set up model fitting workflow
modelfit = pe.Workflow(name='modelfit')

# Use nipype.algorithms.modelgen.SpecifyModel to generate design information
modelspec = pe.Node(interface=model.SpecifyModel(), name="modelspec",output_names="session_info")
modelspec.inputs.input_units = 'secs'
modelspec.inputs.functional_runs = ['/Users/mycomputer/anaconda3/pkgs/nibabel-3.0.0-py_0/site-packages/nibabel/tests/data/functional.nii']
modelspec.inputs.high_pass_filter_cutoff = 0
modelspec.inputs.time_repetition = 0
modelspec.inputs.subject_info = my_subject_info

#Use nipype.interfaces.fsl.Level1Design to generate a run specific fsf file for analysis
level1design = pe.Node(interface=fsl.Level1Design(),
    name="level1design",
    input_names=['session_info'])
level1design.inputs.interscan_interval = 0 
level1design.inputs.bases = {'dgamma':{'derivs': True}} 
level1design.inputs.model_serial_correlations=bool(False) 

# Use nipype.interfaces.fsl.FEATModel to generate a run specific mat file for use by FILMGLS
modelgen = pe.MapNode(
    interface=fsl.FEATModel(),
    name='modelgen',
    iterfield=['fsf_file', 'ev_files'])

# Use nipype.interfaces.fsl.FILMGLS to estimate a model specified by a mat file and a functional run
modelestimate = pe.MapNode(
    interface=fsl.FILMGLS(smooth_autocorr=True, mask_size=5, threshold=1000),
    name='modelestimate',
    iterfield=['design_file', 'in_file'])

### COMBINE NODES & RUN
modelfit.connect([
    (modelspec, level1design, [('session_info', 'session_info')]),
    (level1design, modelgen, [('fsf_files', 'fsf_file'), ('ev_files','ev_files')]),
    (modelgen, modelestimate, [('design_file', 'design_file')])
])

try:
    mdl = modelfit.run()
except(RuntimeError) as err:
    print("RuntimeError:", err)
else:
    raise

From the same shell you’re running your code, can you run feat_model?

Hi thank for your response! I can run feat_model from the command line, but when I try to access it via nipype by using the fsl.FEATModel() command in a node it can’t find the executable file.

How are you running nipype?

I’m running the python script in Spyder and importing the nipype packages as above

It is likely that your PATH inside Spyder doesn’t match your PATH in your shell.

I can’t seem to align them - I’ve tried adding all the fsl and nipype folders to the path in spyder, changing my working directory to where the fsl files are stored, etc. Any suggestions how I might make the feat_model command usable in nipype?

Try running it from the shell, not Spyder? I don’t know what’s required to make Spyder work. You could also try running Spyder from the shell, to ensure the environment variables propagate.

Thanks for your help @effigies - as an update, it was indeed an issue with my spyder path. To fix this I open spyder by navigating in terminal to the file where my fsl files are stored (for me, /usr/local/fsl) and open the IDE from there.