# How to make module modification take effect without restarting the application?

**URL:** <https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420>\
**Category:** Development\
**Created:** [September 18, 2024, 8:09am UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420 "2024-09-18T08:09:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dingdanpeng](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@dingdanpeng](https://discourse.slicer.org/u/dingdanpeng)\
**Post date:** [September 18, 2024, 8:09am UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420/1 "2024-09-18T08:09:56Z")

</div>

Operating system:Win11  
Slicer version:5.7.0  
Every time I modify the plug code, I need to restart the software for it to take effect. Pressing reload does not work. This is because only restart Slicer can take effect or there are other issues?

Expected behavior:reload and The modified code will take effect  
Actual behavior:only restart slicer can take effect

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 18, 2024, 3:02pm UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420/2 "2024-09-18T15:02:42Z")

</div>

If this is python code, you can enable the developer mode (Edit-\>Application Settings), and you can reload the module source code, without having to restart the Slicer application.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/e/be3770ca1f8569a4a6d1bc628ce523d9180988a7.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:** [September 18, 2024, 3:08pm UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420/3 "2024-09-18T15:08:13Z")

</div>

> [@dingdanpeng](#):
>
> Pressing reload does not work.

It does work, so maybe there is something different in your way of using it. A very basic question is whether you have the same folder added to Additional module directories as what you are changing? Because if you built it and you set the `qt-scripted-modules` folder in the build directory, then it only gets refreshed if you do a build or manually copy the Python file (this is why it would help a lot receiving more details in the report, so that one does not have to guess around). Can you please give details about how you store your module code and what folder did you add to Slicer? Also, can you tell us what appears in the Python window when you press Reload? Thanks!

---

<div class="post-metadata">

**Author:** ![dingdanpeng](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@dingdanpeng](https://discourse.slicer.org/u/dingdanpeng)\
**Post date:** [September 19, 2024, 1:54am UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420/4 "2024-09-19T01:54:56Z")

</div>

**I don’t have the qt-scripted-modules folder like the other extensions.**  
**Here is the extension path I added to 3D slicer.**

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

**When i press reload,the Python window appear:**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/7/472f73e456edf15ffc4492df7a883879b8713888.png)

Maybe there’s something wrong with my add path, but how do I set it up correctly ? Thanks!

---

<div class="post-metadata">

**Author:** ![dingdanpeng](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@dingdanpeng](https://discourse.slicer.org/u/dingdanpeng)\
**Post date:** [September 19, 2024, 1:56am UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420/5 "2024-09-19T01:56:32Z")

</div>

I have enabled the developer mode.This more details:  
**I don’t have the qt-scripted-modules folder like the other extensions.**  
**Here is the extension path I added to 3D slicer.**

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

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

**When i press reload,the Python window appear:**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/7/472f73e456edf15ffc4492df7a883879b8713888.png)

Maybe there’s something wrong with my add path, but how do I set it up correctly ? Thanks!

---

<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:** [September 19, 2024, 8:38am UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420/6 "2024-09-19T08:38:26Z")

</div>

Thanks for the information! The problem probably will be that you have a lib folder, and the reload function only reloads the module Python file.

---

<div class="post-metadata">

**Author:** ![JASON](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jason/32/13419_2.png) [@JASON](https://discourse.slicer.org/u/JASON)\
**Post date:** [September 30, 2024, 9:43pm UTC](https://discourse.slicer.org/t/how-to-make-module-modification-take-effect-without-restarting-the-application/38420/7 "2024-09-30T21:43:22Z")

</div>

So the ‘Reload’ button reloads your Module class, but not the external scripts that your class references. The way around this is to manually reload in your module’s init method.

```auto
    def __init__ (self, parent=None) -> None:
        """Called when the user opens the module the first time and the widget is initialized."""
        ScriptedLoadableModuleWidget. __init__ (self, parent)
        VTKObservationMixin. __init__ (self)
        
        import importlib
        import lib
        importlib.reload(lib.dataTransfer)
        importlib.reload(lib.segmentExplorer)

```
