I’m trying to create a scripted python module and I need to perform bias correction over an MRI volume as the first step in the processing pipeline. For this purpose, I intended to call the n4itkbiascorrection CLI module from within the python script. After looking the tutorials in the slicer web page, I understand I should be using ‘slicer.module’ to import the n4itkbiasfieldcorrection module.
I am able to do so from the Python Interactor console via the following code line:
from slicer.modules import n4itkbiasfieldcorrection
However, when using the same code line in the script, the module won’t load and Slicer throws the following error in the python console:
Traceback (most recent call last):
_ File “”, line 1, in _
_ File “/home/miguel/Documentos/Extensiones_3DSlicer/SPAL/SPAL/SPAL.py”, line 12, in _
_ from slicer.modules import n4itkbiasfieldcorrection_ ImportError: cannot import name n4itkbiasfieldcorrection
I tried checking the importable modules via the command:
print(dir(slicer.modules))
When I call this line from the console, the n4itkbiasfieldcorrection module appears in the list printed but it does not appear (along with other many modules) when calling the line from the script.
I am quite new in developing slicer extensions so I am probably missing something here. Any clues on solving this issue??
There is no need to import the module (in addition to the imports that are in the default module template). See description how to run a CLI module from Python in the developer documentation and here is an example in a module:
You are right, don’t know why I assumed I had to import the module. I should have paid more attention to the docs. As you state, if the module is called directly without any importing, it seems to work perfectly.
Hi Andras,
Can I get the link to function that gives parameter information for a cli module?
For your own created python scripted modules if you want to access the parameters how can we access them. Also if there are two apply buttons can these be run from a single module.
for example please see screnn shot for the scripted loadable python module