I have incorporated the hack at the bottom of this help page in order to work with python toolboxes in VS.
The hack works, but if I make changes to the code of any tool therin, save them and then refresh the toolbox in ArcCatalog, the tool runs the old code. It won't run the new code until I restart ArcCatalog, which is anything but fast. Is there anyway to refresh the toolbox without restarting ArcCatalog?
Solved! Go to Solution.
I think (not sure), ArcGIS uses the compiled pyc file unless you explicitly reload the module in your toolbox.
# toolbox.pyt
import importlib
import your_module
importlib.reload(your_module)
from your_module import *
# To see changes made in modules you import in your_module,
# you have to reload them in your_module, too:
# your_module.py
import importlib
import utility_functions
importlib.reload(utility_functions)
from utility_functions import *
Yes, I refreshed the Toolbox as well as the folder containing the Toolbox. This worked when all the code was in the .pyt. It seems that ArcCatalog is storing the code in the .py in memory and not re-reading it when the .pyt that references the .py is refreshed.
I have the same issue when developing scripts for a Python toolbox which import classes or utilities from separate .py files inside the main tool .py file. The only way I can see changes in these files referenced within the tool is by restarting ArcGIS Pro.
If there a solution I would also love to know about it.
I think (not sure), ArcGIS uses the compiled pyc file unless you explicitly reload the module in your toolbox.
# toolbox.pyt
import importlib
import your_module
importlib.reload(your_module)
from your_module import *
# To see changes made in modules you import in your_module,
# you have to reload them in your_module, too:
# your_module.py
import importlib
import utility_functions
importlib.reload(utility_functions)
from utility_functions import *
Brilliant solution. Almost - but only works for ArcGIS Pro.
ArcCatalog is ArcGIS 10.x and thus uses Python 2.7, where this doesn't work. Some digging came up with just
reload(your-module)
or there's another reload in module imp:
import imp
imp.reload(your-module)
which works for python 2 and 3.2-3.3 although I don't think there's Pro version that uses any of these Python versions.
Thanks for putting me on the right path!