Reader small image

You're reading from  Python Scripting in Blender

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781803234229
Edition1st Edition
Right arrow
Author (1)
Paolo Acampora
Paolo Acampora
author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora

Right arrow

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 import reload
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...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Python Scripting in Blender
Published in: Jun 2023Publisher: PacktISBN-13: 9781803234229

Author (1)

author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora