Hi All,
Here's my workflow:
Is there a faster/more convenient way to "refresh" so that script changes are reflected when running the toolbox? I've tried clearing __pycache__ folder in the toolbox folder, but that doesn't do anything.
I'm using Arc Pro 3.0.2.
Thank you,
Solved! Go to Solution.
Hi @HannesZiegler,
Thanks for following up on this, after installing Pro 3.0.3 and confirming that script is not embedded.
I think I figured it out: when I edit the main script specified in the TBX, that edit will be reflected in the toolbox without needed to restart Pro. But if I edit a module script that the main script calls, I need to restart Pro.
Happily, however, I think I resolved even this. By using python's importlib.reload() in the main script I can force the module to reload in the main script, thus incorporating any changes I made to the module.
For example, instead of just putting:
import some_module as sm # module that I want to edit
I enter:
import importlib
import some_module as sm
importlib.reload(sm) # forces reload with every run, so no need to restart Pro
Doing the latter, I can edit the module and re-run in Pro without having to restart Pro.
Cheers,
For a Python toolbox (.pyt):
# Toolbox.pyt
import arcpy
import custom_module
# reload the custom module
import importlib
importlib.reload(custom_module)
class Toolbox():
#...
For script tools, I'm not sure, try refreshing the toolbox in Pro.
Thanks Johannes,
I'm using as a script tool in a toolbox (TBX). I've tried refreshing the toolbox but that doesn't seem to fix it either. Might help if in the main script called by the toolbox if I add importlib.reload() for all modules used by the script.
@DarrenConly, I am unable to reproduce your issue on a later build. Are you able to upgrade to Pro 3.0.3 and reproduce there?
Also, please confirm that you are using .atbx with the script tool exported (vs. embedded). Like this:
Hi @HannesZiegler,
Thanks for following up on this, after installing Pro 3.0.3 and confirming that script is not embedded.
I think I figured it out: when I edit the main script specified in the TBX, that edit will be reflected in the toolbox without needed to restart Pro. But if I edit a module script that the main script calls, I need to restart Pro.
Happily, however, I think I resolved even this. By using python's importlib.reload() in the main script I can force the module to reload in the main script, thus incorporating any changes I made to the module.
For example, instead of just putting:
import some_module as sm # module that I want to edit
I enter:
import importlib
import some_module as sm
importlib.reload(sm) # forces reload with every run, so no need to restart Pro
Doing the latter, I can edit the module and re-run in Pro without having to restart Pro.
Cheers,
Excellent! Thank you for sharing your solution
I had to reload the module, not the class. Otherwise Arc GIS would not load my .pyt file. But I could not find any errors 🤔
from importlib import reload
import some_module
reload(some_module)
from some_module import sm