# Slicer --no-main-window --python-script in windows command prompt not working

**URL:** <https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481>\
**Category:** Development\
**Created:** [April 12, 2019, 3:16pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481 "2019-04-12T15:16:21Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)\
**Post date:** [April 17, 2020, 1:52pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/24 "2020-04-17T13:52:46Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 17, 2020, 2:36pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/25 "2020-04-17T14:36:05Z")

</div>

> [@tbillah](#):
>
> what’s the difference between `SlicerPython` and `PythonSlicer` ?

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](https://github.com/Slicer/Slicer/issues/4843)).

> [@tbillah](#):
>
> On the other hand, when an extension (some python packages) is installed using `ExtensionManger` , which python has knowledge of the python packages?

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.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [April 17, 2020, 3:30pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/26 "2020-04-17T15:30:32Z")

</div>

> [@lassoan](#):
>
> However, this does not seem to be the case. @jcfr do you know why?

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 :

```auto
[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 ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 17, 2020, 5:26pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/27 "2020-04-17T17:26:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [May 5, 2020, 8:00am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/28 "2020-05-05T08:00:20Z")

</div>

This should be fixed in

> <https://github.com/Slicer/Slicer/pull/4912>

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [November 26, 2021, 3:32pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/29 "2021-11-26T15:32:30Z")

</div>

This should now be fixed. Corresponding changes have been integrated.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 15, 2023, 3:31am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/30 "2023-08-15T03:31:21Z")

</div>

Dear Andras,  
how can we run the slicer python scripted module from the command line?

regards,  
Saima

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 15, 2023, 5:28am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/31 "2023-08-15T05:28:00Z")

</div>

You can start the application, instantiate its logic class, and call method of that logic object.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 15, 2023, 6:34am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/32 "2023-08-15T06:34:45Z")

</div>

> [@lassoan](#):
>
> n start the application

should i be doing this slicer.exe --python-code “instructions you specified seperated by comma” --no-main-window

regards,  
Saima

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 16, 2023, 2:15am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/33 "2023-08-16T02:15:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 16, 2023, 2:18am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/34 "2023-08-16T02:18:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 16, 2023, 12:07pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/35 "2023-08-16T12:07:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 17, 2023, 1:21am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/36 "2023-08-17T01:21:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 17, 2023, 12:58pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/37 "2023-08-17T12:58:03Z")

</div>

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`](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository/gui.html#run-a-python-script-file-in-the-slicer-environment)).

---

<div class="post-metadata">

**Author:** ![William\_Kuo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_kuo/32/65525_2.png) [@William\_Kuo](https://discourse.slicer.org/u/William_Kuo)\
**Post date:** [February 20, 2024, 1:16am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/38 "2024-02-20T01:16:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 24, 2024, 2:35am UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/39 "2024-02-24T02:35:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ckolluru](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@ckolluru](https://discourse.slicer.org/u/ckolluru)\
**Post date:** [March 15, 2024, 4:36pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/40 "2024-03-15T16:36:29Z")

</div>

I probably have a similar issue. When I run the following command:

```auto
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?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 15, 2024, 4:43pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/41 "2024-03-15T16:43:53Z")

</div>

If there’s no mainWindow, there will be no threeDWidget either.

Maybe you want something like this:

```auto
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.

---

<div class="post-metadata">

**Author:** ![ckolluru](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@ckolluru](https://discourse.slicer.org/u/ckolluru)\
**Post date:** [March 15, 2024, 5:01pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/42 "2024-03-15T17:01:17Z")

</div>

Thank you. I think this should work.

[Previous page](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481.md?page=1)
