Python code can be used in many parts of ArcGIS Pro. Sometimes an integrated development environment (IDE) is necessary to debug code. Use a Python IDE to author and troubleshoot script tool and Python toolbox source and validation code.
Use the arcpy.SetupDebugger() function to debug script tools. Insert this function after the import statements in your code, before debugging the script. You may need to place the function inside individual function definitions if breakpoints are not detected there. When you finish debugging, remove all instances of arcpy.SetupDebugger(). ArcGIS Pro is a multithreaded application, and debuggers do not automatically recognize the thread running ArcGIS Pro code. The arcpy.SetupDebugger() function uses the debugpy module to help the debugger attach to the correct thread. The debugpy package is a Python package that supports debugging Python code with various IDEs.
Microsoft Visual Studio Code
The following ArcGIS Pro components can be debugged in Visual Studio Code:
- Script tool code (source, validation)
- Python toolboxes code (source, validation)
Use the ArcGIS Pro Debugger Extension for Visual Studio Code to debug script tools. The ArcGIS Pro debug mode can be set from the Visual Studio Code extension, removing the need for explicitly managing arcpy.SetupDebugger() calls in your code.
Microsoft Visual Studio
The following ArcGIS Pro components can be debugged in Visual Studio:
- Script tool code (source, validation)
- Python toolboxes code (source, validation)
PyCharm Professional edition
The following ArcGIS Pro components can be debugged in PyCharm Professional edition:
- Script tool code (source, validation)
- Python toolboxes code (source, validation)
pdb module
The pdb module is part of the Python standard library. It is not a fully developed IDE, but it can be used for interactive source code debugging. Although you cannot use the pdb module to debug in ArcGIS Pro, you can use it to debug stand-alone scripts, including the source code for script tools.
The pdb module is useful for debugging a script tool's source code running in a stand-alone Python script. Add a breakpoint using the breakpoint function to the script tool's code, and run a Python script that calls that script tool. Upon encountering the breakpoint, Python will enter interactive mode. Remove the breakpoint code upon completion of the debugging effort.