@lassoan, another relevant question, what’s the difference between SlicerPython
and PythonSlicer
?
I understand that the PythonInteractor
runs PythonSlicer
though. On the other hand, when an extension (some python packages) is installed using ExtensionManger
, which python has knowledge of the python packages?
We had to rename SlicerPython to PythonSlicer, because some Python IDEs (specifically PyCharm, but potentially others) only recognized Python*.exe files as Python interpreters. We have not removed SlicerPython for backward compatibility but eventually it will go away (see related issue).
My understanding is that regardless of which launcher (Slicer.exe or PythonSlicer.exe) executes python-real.exe, extensions should be added to path/pythonpath. However, this does not seem to be the case. @jcfr do you know why?
Slicer modules will only be available if you execute SlicerApp-real.exe.
To ensure it includes the PATH
and PYTHONPATHS
associated with Slicer extensions are also available, the additional launcher settings for the associated revision of Slicer need to be loaded.
In the Slicer launcher, that mapping is described by the following :
[Application]
name=Slicer
revision=28975
organizationDomain=www.na-mic.org
organizationName=NA-MIC
This ensured setting file like /home/jcfr/.config/NA-MIC/Slicer-28975.ini
is found by the launcher.
If you manually add a similar section to the settings of PythonSlicer
, could you check the extension settings are found ?
Thanks for the explanation. Adding application name, revision, and organizationName fixes the problem!
@jcfr what do you think about adding these lines to PythonSlicer launcher settings so that Python modules, DLLs, and executables provided by extensions can be found when using Slicer’s Python environment? I think these would be useful when using Python IDEs or running batch processing scripts.
This should be fixed in
This should now be fixed. Corresponding changes have been integrated.
Dear Andras,
how can we run the slicer python scripted module from the command line?
regards,
Saima
You can start the application, instantiate its logic class, and call method of that logic object.
should i be doing this slicer.exe --python-code “instructions you specified seperated by comma” --no-main-window
regards,
Saima
Hi Andras,
Could you please tell me what is wrong in the below command line
(base) useradmin@DEP59365:/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64$ **
./Slicer --python-code “s=getModuleLogic(‘SurfaceModelNodesSelector’);s.process(”/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/25_manually_picking_points/models")" --no-splash --testing --no-main-window
**
qSlicerMarkupsModulePrivate::addToolBar: no main window is available, toolbar is not added
qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added
File “”, line 1
s=getModuleLogic(‘SurfaceModelNodesSelector’);s.process(/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/25_manually_picking_points/models)
^
SyntaxError: invalid syntax
double free or corruption (!prev)
error: [/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/bin/SlicerApp-real] exit abnormally - Report the problem.
The module i am trying to run is not a registered module. can I still run using command line??
(base) useradmin@DEP59365:/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64$ ./Slicer --python-code “s=getModuleLogic(‘SurfaceModelNodesSelector’);s.process(‘/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/25_manually_picking_points/models’)” --no-splash --testing --no-main-window
qSlicerMarkupsModulePrivate::addToolBar: no main window is available, toolbar is not added
qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added
The module “SurfaceModelNodesSelector” has not been registered.
The following modules have been registered: (“ACPCTransform”, “AddManyMarkupsFiducialTest”, “AddScalarVolumes”, “Annotations”, “AtlasTests”, “BRAINSDWICleanup”, “BRAINSDeface”, “BRAINSFit”, “BRAINSFitRigidRegistrationCrashIssue4139”, “BRAINSIntensityNormalize”, “BRAINSROIAuto”, “BRAINSResample”, “BRAINSResize”, “BRAINSStripRotation”, “BRAINSTransformConvert”, “Cameras”, “CastScalarVolume”, “CheckerBoardFilter”, “ColorLegendSelfTest”, “Colors”, “CompareVolumes”, “CreateDICOMSeries”, “CropVolume”, “CropVolumeSelfTest”, “CropVolumeSequence”, “CurvatureAnisotropicDiffusion”, “DICOM”, “DICOMEnhancedUSVolumePlugin”, “DICOMGeAbusPlugin”, “DICOMImageSequencePlugin”, “DICOMPatcher”, “DICOMScalarVolumePlugin”, “DICOMSlicerDataBundlePlugin”, “DICOMVolumeSequencePlugin”, “DMRIInstall”, “DWIConvert”, “Data”, “DataProbe”, “Decimation”, “DynamicModeler”, “Endoscopy”, “EventBroker”, “ExecutionModelTour”, “ExtensionWizard”, “ExtractSkeleton”, “FiducialLayoutSwitchBug1914”, “FiducialRegistration”, “GaussianBlurImageFilter”, “GradientAnisotropicDiffusion”, “GrayscaleFillHoleImageFilter”, “GrayscaleGrindPeakImageFilter”, “GrayscaleModelMaker”, “HistogramMatching”, “ImageLabelCombine”, “ImportItkSnapLabel”, “JRC2013Vis”, “LabelMapSmoothing”, “LandmarkRegistration”, “Markups”, “MarkupsInCompareViewersSelfTest”, “MarkupsInViewsSelfTest”, “MaskScalarVolume”, “MedianImageFilter”, “MergeModels”, “ModelMaker”, “ModelToLabelMap”, “Models”, “MultiVolumeExplorer”, “MultiVolumeImporter”, “MultiVolumeImporterPlugin”, “MultiplyScalarVolumes”, “N4ITKBiasFieldCorrection”, “NeurosurgicalPlanningTutorialMarkupsSelfTest”, “OrientScalarVolume”, “PETStandardUptakeValueComputation”, “PerformMetricTest”, “PerformanceTests”, “Plots”, “PlotsSelfTest”, “PluggableMarkupsSelfTest”, “ProbeVolumeWithModel”, “RSNA2012ProstateDemo”, “RSNAQuantTutorial”, “RSNAVisTutorial”, “Reformat”, “ResampleDTIVolume”, “ResampleScalarVectorDWIVolume”, “ResampleScalarVolume”, “RobustStatisticsSegmenter”, “SampleData”, “ScenePerformance”, “SceneViews”, “ScreenCapture”, “SegmentEditor”, “SegmentStatistics”, “Segmentations”, “SelfTests”, “Sequences”, “ShaderProperties”, “SimpleFilters”, “SimpleRegionGrowingSegmentation”, “SliceLinkLogic”, “Slicer4Minute”, “SlicerBoundsTest”, “SlicerMRBMultipleSaveRestoreLoopTest”, “SlicerMRBMultipleSaveRestoreTest”, “SlicerMRBSaveRestoreCheckPathsTest”, “SlicerOrientationSelectorTest”, “SlicerScriptedFileReaderWriterTest”, “SlicerTransformInteractionTest1”, “SubjectHierarchy”, “SubjectHierarchyCorePluginsSelfTest”, “SubjectHierarchyGenericSelfTest”, “SubtractScalarVolumes”, “SurfaceToolbox”, “Tables”, “TablesSelfTest”, “Terminologies”, “Texts”, “ThresholdScalarVolume”, “Transforms”, “Units”, “UtilTest”, “VectorToScalarVolume”, “ViewControllers”, “ViewControllersSliceInterpolationBug1926”, “VolumeRendering”, “VolumeRenderingSceneClose”, “Volumes”, “VotingBinaryHoleFillingImageFilter”, “WebEngine”, “WebServer”, “Welcome”, “sceneImport2428”)
Traceback (most recent call last):
File “”, line 1, in
File “/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/bin/Python/slicer/util.py”, line 1275, in getModuleLogic
module = getModule(module)
File “/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/bin/Python/slicer/util.py”, line 1196, in getModule
raise RuntimeError(“Could not find module with name ‘%s’” % moduleName)
RuntimeError: Could not find module with name ‘SurfaceModelNodesSelector’
double free or corruption (!prev)
error: [/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/bin/SlicerApp-real] exit abnormally - Report the problem.
You need to use "
for marking the start and end of the Python code in the command-line argument list, therefore you can only use '
in the python code. The fix is to replace all "
by '
in the Python code that you pass via the command-line argument.
I did what you recommended and have the following:
The module i am trying to run is not a registered module. can I still run using command line??
(base) useradmin@DEP59365:/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64$ ./Slicer --python-code “s=getModuleLogic(‘SurfaceModelNodesSelector’);s.process(‘/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/25_manually_picking_points/models’)” --no-splash --testing --no-main-window
qSlicerMarkupsModulePrivate::addToolBar: no main window is available, toolbar is not added
qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added
The module “SurfaceModelNodesSelector” has not been registered.
The following modules have been registered: (“ACPCTransform”, “AddManyMarkupsFiducialTest”, “AddScalarVolumes”, “Annotations”, “AtlasTests”, “BRAINSDWICleanup”, “BRAINSDeface”, “BRAINSFit”, “BRAINSFitRigidRegistrationCrashIssue4139”, “BRAINSIntensityNormalize”, “BRAINSROIAuto”, “BRAINSResample”, “BRAINSResize”, “BRAINSStripRotation”, “BRAINSTransformConvert”, “Cameras”, “CastScalarVolume”, “CheckerBoardFilter”, “ColorLegendSelfTest”, “Colors”, “CompareVolumes”, “CreateDICOMSeries”, “CropVolume”, “CropVolumeSelfTest”, “CropVolumeSequence”, “CurvatureAnisotropicDiffusion”, “DICOM”, “DICOMEnhancedUSVolumePlugin”, “DICOMGeAbusPlugin”, “DICOMImageSequencePlugin”, “DICOMPatcher”, “DICOMScalarVolumePlugin”, “DICOMSlicerDataBundlePlugin”, “DICOMVolumeSequencePlugin”, “DMRIInstall”, “DWIConvert”, “Data”, “DataProbe”, “Decimation”, “DynamicModeler”, “Endoscopy”, “EventBroker”, “ExecutionModelTour”, “ExtensionWizard”, “ExtractSkeleton”, “FiducialLayoutSwitchBug1914”, “FiducialRegistration”, “GaussianBlurImageFilter”, “GradientAnisotropicDiffusion”, “GrayscaleFillHoleImageFilter”, “GrayscaleGrindPeakImageFilter”, “GrayscaleModelMaker”, “HistogramMatching”, “ImageLabelCombine”, “ImportItkSnapLabel”, “JRC2013Vis”, “LabelMapSmoothing”, “LandmarkRegistration”, “Markups”, “MarkupsInCompareViewersSelfTest”, “MarkupsInViewsSelfTest”, “MaskScalarVolume”, “MedianImageFilter”, “MergeModels”, “ModelMaker”, “ModelToLabelMap”, “Models”, “MultiVolumeExplorer”, “MultiVolumeImporter”, “MultiVolumeImporterPlugin”, “MultiplyScalarVolumes”, “N4ITKBiasFieldCorrection”, “NeurosurgicalPlanningTutorialMarkupsSelfTest”, “OrientScalarVolume”, “PETStandardUptakeValueComputation”, “PerformMetricTest”, “PerformanceTests”, “Plots”, “PlotsSelfTest”, “PluggableMarkupsSelfTest”, “ProbeVolumeWithModel”, “RSNA2012ProstateDemo”, “RSNAQuantTutorial”, “RSNAVisTutorial”, “Reformat”, “ResampleDTIVolume”, “ResampleScalarVectorDWIVolume”, “ResampleScalarVolume”, “RobustStatisticsSegmenter”, “SampleData”, “ScenePerformance”, “SceneViews”, “ScreenCapture”, “SegmentEditor”, “SegmentStatistics”, “Segmentations”, “SelfTests”, “Sequences”, “ShaderProperties”, “SimpleFilters”, “SimpleRegionGrowingSegmentation”, “SliceLinkLogic”, “Slicer4Minute”, “SlicerBoundsTest”, “SlicerMRBMultipleSaveRestoreLoopTest”, “SlicerMRBMultipleSaveRestoreTest”, “SlicerMRBSaveRestoreCheckPathsTest”, “SlicerOrientationSelectorTest”, “SlicerScriptedFileReaderWriterTest”, “SlicerTransformInteractionTest1”, “SubjectHierarchy”, “SubjectHierarchyCorePluginsSelfTest”, “SubjectHierarchyGenericSelfTest”, “SubtractScalarVolumes”, “SurfaceToolbox”, “Tables”, “TablesSelfTest”, “Terminologies”, “Texts”, “ThresholdScalarVolume”, “Transforms”, “Units”, “UtilTest”, “VectorToScalarVolume”, “ViewControllers”, “ViewControllersSliceInterpolationBug1926”, “VolumeRendering”, “VolumeRenderingSceneClose”, “Volumes”, “VotingBinaryHoleFillingImageFilter”, “WebEngine”, “WebServer”, “Welcome”, “sceneImport2428”)
Traceback (most recent call last):
File “”, line 1, in
File “/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/bin/Python/slicer/util.py”, line 1275, in getModuleLogic
module = getModule(module)
File “/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/bin/Python/slicer/util.py”, line 1196, in getModule
raise RuntimeError(“Could not find module with name ‘%s’” % moduleName)
RuntimeError: Could not find module with name ‘SurfaceModelNodesSelector’
double free or corruption (!prev)
error: [/media/useradmin/Disk2/Slicer-5.3.0-2023-01-21-linux-amd64/bin/SlicerApp-real] exit abnormally - Report the problem.
You can only use modules that are loaded. You can add the module to the additional module paths before launching Slicer or you can run a Python script instead of calling methods of a Python-scripted module (using --python-script /path/to/myscript.py
).
Hi!
I am having the same issue.
The first script does not works:
slicerCommand = r"Slicer.exe --python-script {} --no-splash --no-main-window".format(slicerScript)
The second script works:
slicerCommand = r"Slicer.exe --python-script {}".format(slicerScript)
I input these commands into os.system()
I process segmentations and export stl with these scripts. I can see the result of my processing with the second script through an stl output, but I don’t see it with the first script, no stl file is outputted.
The only difference is that my slicer script is ran without a GUI, which is substantially faster. This is relevant because I work with large datasets and my focus is on automating and accelerating a pipeline.
You will not have access to many Slicer functions that are related to the GUI if you disable the main window. To make batch orocessing faster, I would recommend to laun h several Slicer instances (as many as your computer can handle) and run many commands on it (e.g., if you need to process 2000 patient data then don’t start a new Slicer instance for each but process 100 patients before restarting Slicer). You can use SlicerWeb module to send commands to an already running Slicer.
I probably have a similar issue. When I run the following command:
layoutManager = slicer.app.layoutManager()
threeDWidget = layoutManager.threeDWidget(0)
It works fine in the python console of Slicer application. However, running it with the -no-main-window option returns a NoneType
object for layoutManager
. Is there a workaround?
If there’s no mainWindow, there will be no threeDWidget either.
Maybe you want something like this:
Slicer --python-code "slicer.util.mainWindow().hide(); print(slicer.app.layoutManager().threeDWidget(0))"
where the main window is offscreen. You should still be able to render and screen grab from the widget, but you’ll need to test as the behavior may not be defined across platforms.
Thank you. I think this should work.