# segLg = slicer.modules.segmentations.logic() AttributeError: module 'modules' has no attribute 'segmentations'

**URL:** <https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [October 3, 2025, 1:26pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660 "2025-10-03T13:26:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 1:26pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/1 "2025-10-03T13:26:59Z")

</div>

Are the modules not fully imported? What’s wrong in py?

> > > segLg = slicer.modules.segmentations.logic()  
> > > AttributeError: module ‘modules’ has no attribute ‘segmentations’  
> > > print(dir(slicer.modules))  
> > > [‘AddManyMarkupsFiducialTestInstance’, ‘AtlasTestsInstance’, ‘BRAINSFitRigidRegistrationCrashIssue4139Instance’, ‘ColorLegendSelfTestInstance’, ‘CompareVolumesInstance’, ‘CropVolumeSelfTestInstance’, ‘CropVolumeSequenceInstance’, ‘DICOMEnhancedUSVolumePluginInstance’, ‘DICOMGeAbusPluginInstance’, ‘DICOMImageSequencePluginInstance’, ‘DICOMInstance’, ‘DICOMPatcherInstance’, ‘DICOMScalarVolumePluginInstance’, ‘DICOMSlicerDataBundlePluginInstance’, ‘DICOMVolumeSequencePluginInstance’, ‘DataProbeInstance’, ‘EndoscopyInstance’, ‘ExtensionWizardInstance’, ‘FiducialLayoutSwitchBug1914Instance’, ‘ImportItkSnapLabelInstance’, ‘JRC2013VisInstance’, ‘JupyterNotebooksInstance’, ‘LandmarkRegistrationInstance’, ‘MarkupsInCompareViewersSelfTestInstance’, ‘MarkupsInViewsSelfTestInstance’, ‘MultiVolumeImporterInstance’, ‘MultiVolumeImporterPluginInstance’, ‘NeurosurgicalPlanningTutorialMarkupsSelfTestInstance’, ‘ **doc** ’, ‘ **file** ’, ‘ **loader** ’, ‘ **name** ’, ‘ **package** ’, ‘ **spec** ’, ‘dicomPlugins’, ‘registrationPlugins’]

However in `python console` this situation does not occur.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/3/c30a048eb3989a7ef7649d5cc11a3a55afa2bfc8.png)

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 3, 2025, 1:30pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/2 "2025-10-03T13:30:38Z")

</div>

Is it a build you did yourself or downloaded and installed?

Are there any errors on startup?

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 1:32pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/3 "2025-10-03T13:32:56Z")

</div>

downloaded and installed from [https://download.slicer.org/bitstream/67c52e9629825655577d0353](https://download.slicer.org/bitstream/67c52e9629825655577d0353)

---

<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:** [October 3, 2025, 1:59pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/4 "2025-10-03T13:59:21Z")

</div>

That is Slicer 5.8.1 for mac, and when I run it this works:

```auto
>>> slicer.modules.segmentations.logic()
<vtkSlicerSegmentationsModuleLogicPython.vtkSlicerSegmentationsModuleLogic(0x600003b38af0) at 0x1b4b7f100>

```

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 3, 2025, 2:01pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/5 "2025-10-03T14:01:58Z")

</div>

> [@cpinter](#):
>
> Are there any errors on startup?

Please answer this question too, this is the more important one. Thanks

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 2:03pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/6 "2025-10-03T14:03:30Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/0/d0e04a4fd85272820b55d82c1a4377a5a7837ccc.png)

---

<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:** [October 3, 2025, 2:05pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/7 "2025-10-03T14:05:27Z")

</div>

You’ll need to narrow down to something reproducible or we can’t help you out.

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 2:22pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/8 "2025-10-03T14:22:35Z")

</div>

```auto
# ...docs/segLg.py
import slicer
segLg = slicer.modules.segmentations.logic()

```

For example, add the above file docs/segLg.py to modules as follows:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/b/abfd34ed99a047640725ffc9a85c9de69d827293.png)

\*\*The error is as follows:\*\*

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/c/5c776c3319fd02da233ba096d5c9c79c836b47cd.png)

---

<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:** [October 3, 2025, 2:58pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/9 "2025-10-03T14:58:53Z")

</div>

Ah, okay. Your module is being discovered before the segmentations has loaded.

You need something like:

```auto
self.parent.dependencies = ["Segmentations"]

```

in your module’s main class.

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 3:09pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/10 "2025-10-03T15:09:12Z")

</div>

@pieper For example, how to modify `segLg.py` 👇?

```auto
import slicer
# ? self.parent.dependencies = ["Segmentations"]
segLg = slicer.modules.segmentations.logic()

```

---

<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:** [October 3, 2025, 3:11pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/11 "2025-10-03T15:11:48Z")

</div>

Since you added this `docs` path to the module path it needs to be in the scripted module format, like you get when you use the ExtensionWizard. That’s there the dependency is expressed.

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 3:18pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/12 "2025-10-03T15:18:06Z")

</div>

@pieper Teacher, could you be more specific? Could you give an example🌰?

---

<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:** [October 3, 2025, 3:20pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/13 "2025-10-03T15:20:04Z")

</div>

Like here:

> <https://github.com/Slicer/Slicer/blob/main/Modules/Scripted/Endoscopy/Endoscopy.py#L34>

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 3:45pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/14 "2025-10-03T15:45:14Z")

</div>

```auto
import slicer
# self.parent.dependencies = ["Segmentations"]
print(f'{dir(slicer.modules)=}')
segLg = slicer.modules.segmentations.logic()

```

```auto
dir(slicer.modules)=['AddManyMarkupsFiducialTestInstance', 'AtlasTestsInstance', 'BRAINSFitRigidRegistrationCrashIssue4139Instance', 'ColorLegendSelfTestInstance', 'CompareVolumesInstance', 'CropVolumeSelfTestInstance', 'CropVolumeSequenceInstance', 'DICOMEnhancedUSVolumePluginInstance', 'DICOMGeAbusPluginInstance', 'DICOMImageSequencePluginInstance', 'DICOMInstance', 'DICOMPatcherInstance', 'DICOMScalarVolumePluginInstance', 'DICOMSlicerDataBundlePluginInstance', 'DICOMVolumeSequencePluginInstance', 'DataProbeInstance', 'EndoscopyInstance', 'ExtensionWizardInstance', 'FiducialLayoutSwitchBug1914Instance', 'ImportItkSnapLabelInstance', 'JRC2013VisInstance', 'JupyterNotebooksInstance', 'LandmarkRegistrationInstance', 'MarkupsInCompareViewersSelfTestInstance', 'MarkupsInViewsSelfTestInstance', 'MultiVolumeImporterInstance', 'MultiVolumeImporterPluginInstance', 'NeurosurgicalPlanningTutorialMarkupsSelfTestInstance', 'PedicleScrewPlannerInstance', 'PedicleScrewSimulatorInstance', 'PedicleTrianglePlannerInstance', 'PerformanceTestsInstance', 'PlotsSelfTestInstance', 'PluggableMarkupsSelfTestInstance', 'PyTorchUtilsInstance', 'RSNA2012ProstateDemoInstance', 'RSNAQuantTutorialInstance', 'RSNAVisTutorialInstance', 'SampleDataInstance', 'ScenePerformanceInstance', 'ScreenCaptureInstance', 'SegmentEditorInstance', 'SegmentStatisticsInstance', 'SelfTestsInstance', 'SequencesSelfTestInstance', 'ShaderPropertiesInstance', 'SimpleFiltersInstance', 'SliceLinkLogicInstance', 'Slicer4MinuteInstance', 'SlicerBoundsTestInstance', 'SlicerDisplayNodeSequenceTestInstance', 'SlicerMRBMultipleSaveRestoreLoopTestInstance', 'SlicerMRBMultipleSaveRestoreTestInstance', 'SlicerMRBSaveRestoreCheckPathsTestInstance', 'SlicerNNUNetInstance', 'SlicerOrientationSelectorTestInstance', 'SlicerPythonTestRunnerInstance', 'SlicerScriptedFileReaderWriterTestInstance', 'SubjectHierarchyCorePluginsSelfTestInstance', 'SubjectHierarchyGenericSelfTestInstance', 'SurfaceToolboxInstance', 'TablesSelfTestInstance', 'TotalSegmentatorInstance', 'UtilTestInstance', 'VectorToScalarVolumeInstance', 'ViewControllersSliceInterpolationBug1926Instance', 'VolumeRenderingSceneCloseInstance', 'WebEngineInstance', 'WebServerInstance', ' __doc__', ' __file__', ' __loader__', ' __name__', ' __package__', ' __spec__', 'dicomPlugins', 'registrationPlugins', 'sampleDataSources', 'sceneImport2428Instance']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.9/imp.py", line 169, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 613, in _exec
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/liguimei/Documents/ppPrj/Resources/docs/segLg.py", line 4, in <module>
    segLg = slicer.modules.segmentations.logic()
AttributeError: module 'modules' has no attribute 'segmentations'
[Qt] loadSourceAsModule - Failed to load file "/Users/liguimei/Documents/ppPrj/Resources/docs/segLg.py" as module "segLg" !
[Qt] Fail to instantiate module "segLg"

```

Still don’t understand…

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 3, 2025, 4:07pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/15 "2025-10-03T16:07:03Z")

</div>

@lassoan ?…………………………………………….

---

<div class="post-metadata">

**Author:** ![shai-ikko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shai-ikko/32/15765_2.png) [@shai-ikko](https://discourse.slicer.org/u/shai-ikko)\
**Post date:** [October 16, 2025, 7:49am UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/16 "2025-10-16T07:49:05Z")

</div>

Slicer has some expectations from files you try to use as modules. If you just drop some python code into a file, it can break, and that is what you see.

The particular expectation here is: It should be possible to import your file without it depending on other modules. Your code explicitly depends on other modules.

Re-writing the file so that it looks like the module shown by @pieper would help:

- The code that uses `slicer.modules.segmentations` should be in one of the method of the class, so it doesn’t get executed at import time
- Then you also have a place to declare dependencies, which will be respected

Trying to add one line to your existing code would not work.

---

<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:** [October 16, 2025, 12:15pm UTC](https://discourse.slicer.org/t/seglg-slicer-modules-segmentations-logic-attributeerror-module-modules-has-no-attribute-segmentations/44660/17 "2025-10-16T12:15:13Z")

</div>

I would recommend to use the Extensions Wizard module to generate a module skeleton and add your code to it piece by piece. The [STC-DEV-101 Tutorial](https://training.slicer.org/#STC-DEV-101) should help.
