Hi,
Before 3.3, I was able to debug Python geoprocessing tools. For development, I use Visual Studio 2022, but I was still unable to debug the scripts there. The workaround was to use Visual Studio 2019 by attaching the Pro process to it.
However, after migrating to version 3.3, that workaround no longer works.
Can anyone guide me on how to debug Python scripts for geoprocessing tools in version 3.3, or suggest any new workarounds?
@AlfredBaldenweck @HaydenWelch @BlakeTerhune @JakeSkinner
for reference, you are saying the information below no longer works?
Debug Python code—ArcGIS Pro | Documentation
@DanPatterson Yes. But anyways previously as well it was not working, had to use a VS 2022 for development but for debugging I was using VS 2019. But now after migrating to Pro 3.3 even the workaround of debugging using VS 2019 is also not working.
I don't use Visual Studio much because I find it to be a bit overbearing for Python development and prefer VS Code for my style of programming.
For debugging, I usually just shadow the print function using this code:
def print(*values: object,
sep: str = " ",
end: str = "\n",
file = None,
flush: bool = False,
severity: Literal['INFO', 'WARNING', 'ERROR'] = None):
""" Print a message to the ArcGIS Pro message queue and stdout
set severity to 'WARNING' or 'ERROR' to print to the ArcGIS Pro message queue with the appropriate severity
"""
# Import the builtins module for the standard print function
import builtins
# Print the message to stdout
builtins.print(*values, sep=sep, end=end, file=file, flush=flush)
end = "" if end == '\n' else end
message = f"{sep.join(map(str, values))}{end}"
# Print the message to the ArcGIS Pro message queue with the appropriate severity
match severity:
case "WARNING":
arcpy.AddWarning(f"{message}")
case "ERROR":
arcpy.AddError(f"{message}")
case _:
arcpy.AddMessage(f"{message}")
return
That will let you use the standard print function to print to the message box when you run a tool from Pro. You can also just use standard breakpoints and such from VS Code if your script doesn't rely on the PYT system.