Reloading cached modules
When a module is imported, Python caches a copy of it for future access. Since the __init__.py
file is the only one to be updated by the Reload Scripts operator, we are left with two options:
- Close and restart Blender
- Explicitly call the
reload
function inside__init__.py
The latter is preferred over restarting the application as it takes less time. The reload
function is part of the importlib
module.
Reloading via importlib
The utilities contained in the importlib
library interact with the import system, and the reload
function forces the Python interpreter to reload a module from disk.
If the img_loader
module has changed and needs to be reloaded, we can use the following command:
from importlib importreload
reload(img_loader)
So, to make sure that the changes to our add-on .py
files are always applied, we can add these lines of code to _init_.py
:
from . import img_loader from . import panel from importlib import reload...