Python Mrtrix3 FSL configuration

Dear,
I am new to Mrtrix3 and I am using the Mrtrix3 command in python script. I could run the Mrtrix3 command in linux terminal, but in python, I am troubled with the following question.

1 Like

Hi - here’s a relevant FSL page for setting up the $FSLDIR variable. In short, you need to let the computer know where FSL has been installed on the computer. To ensure that this path is available across terminal sessions, you could add the line FSLDIR=/path/to/fsl to your ~/.bash_profile. (And, of course, this is assuming you followed MRtrix3 installation instructions and also installed FSL!)

Thanks for your kindly reply. I have installed FSL and MRtrix3, and I could run the MRtrix3 commond in the linux terminal, but could not run the same command in the python enviroment. Should I import or configure the FSL in python?

1 Like

How exactly do you run the command from Python? Using the MRtrix3 Python scripting library or using the subprocess module?

If you’re using subprocess methods, they should inherit environment variables from the current process’ environment. I’d start with debugging your environment variables in python (inspect os.environ) and then using the method you call dwifslpreproc from. For instance, subprocess.check_output('env', shell=False). If needed, you can modify the environment with the env keyword argument, for instance env={**os.environ, **{'FSLDIR': '/usr/local/fsl', 'FSLOUTPUTTYPE': 'NIFTI_GZ'}}.

1 Like