Select to view content in your preferred language

Need to restart Pro every time I edit a toolbox's scripts

1000
6
Jump to solution
10-19-2022 03:35 PM
DarrenConly
Occasional Contributor

Hi All,

Here's my workflow:

  1. Run toolbox in Pro. Toolbox refers to custom python scripts that I wrote.
  2. Make tweak/edit in python script.
  3. I *want* to be able to just re-run the tool in Pro after making the tweaks. However, in order for the script tweaks to have effect, I usually (though not always) have to restart Pro, which is annoying.

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,

Tags (3)
1 Solution

Accepted Solutions
DarrenConly
Occasional Contributor

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,

View solution in original post

6 Replies
JohannesLindner
MVP Frequent Contributor

For a Python toolbox (.pyt):

  • in the pyt, reload the imported modules. this will recompile it into the pycache folder
  • refresh the toolbox in Pro. this will make it reread the pycache
# Toolbox.pyt
import arcpy
import custom_module

# reload the custom module
import importlib
importlib.reload(custom_module)

class Toolbox():
    #...

 

JohannesLindner_0-1666248916865.png

 

 

For script tools, I'm not sure, try refreshing the toolbox in Pro.


Have a great day!
Johannes
DarrenConly
Occasional Contributor

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.

0 Kudos
HannesZiegler
Esri Contributor

@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:

HannesZiegler_0-1671573048850.png

 

0 Kudos
DarrenConly
Occasional Contributor

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,

HannesZiegler
Esri Contributor

Excellent! Thank you for sharing your solution

0 Kudos
MortenBackNielsen
New Contributor

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

 

0 Kudos