# Package imp deprecated

**URL:** <https://discourse.slicer.org/t/package-imp-deprecated/7797>\
**Category:** Development\
**Tags:** python\
**Created:** [July 29, 2019, 1:56pm UTC](https://discourse.slicer.org/t/package-imp-deprecated/7797 "2019-07-29T13:56:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [July 29, 2019, 1:56pm UTC](https://discourse.slicer.org/t/package-imp-deprecated/7797/1 "2019-07-29T13:56:36Z")

</div>

The package imp is [deprecated](https://docs.python.org/3/library/imp.html) in python since version 3.4 and will be removed. This is critical as the button reload of the modules strongly depends on this package. I didn’t succeed to replace it with the recommended importlib, but maybe somebody has already created something.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [July 31, 2019, 9:26am UTC](https://discourse.slicer.org/t/package-imp-deprecated/7797/2 "2019-07-31T09:26:13Z")

</div>

I have tried overriding the onReload method, it runs without error but it does not do what it is intended, the submodules are still not reloaded:

```python
def onReload(self):
        """
        Override reload scripted module widget representation.
        """
        logging.debug("Reloading Dosimetry4D")
        submoduleNames=['Dosimetry4DLogic', 'Dosimetry4DTest', 'fit_values', 'PhysicalUnits']
        import importlib
        for submoduleName in submoduleNames:
            module = importlib.import_module(".".join(['Logic', submoduleName]))
            importlib.reload(module)
            
        if isinstance(self, ScriptedLoadableModuleWidget): # Mandatory for now, reloading the widget
            ScriptedLoadableModuleWidget.onReload(self)

```

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [August 6, 2019, 1:18pm UTC](https://discourse.slicer.org/t/package-imp-deprecated/7797/3 "2019-08-06T13:18:04Z")

</div>

I made it to work with the following:

```python
import importlib
mod = importlib.import_module('Logic', __name__ )
importlib.reload(mod)
__submoduleNames__ =['Dosimetry4DLogic', 'Dosimetry4DTest', 'fit_values', 'PhysicalUnits']

# and then...
    def onReload(self):
        """
        Override reload scripted module widget representation.
        """
        logging.info("Reloading Dosimetry4D")
        importlib.reload(mod)
        for submoduleName in __submoduleNames__ :
            mod1 = importlib.import_module('.'.join(['Logic',submoduleName]), __name__ )
            importlib.reload(mod1)

        if isinstance(self, ScriptedLoadableModuleWidget):
             ScriptedLoadableModuleWidget.onReload(self)

```
