Debug Python code
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 tools and Python toolbox source and validation code.
ArcGIS Pro 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.
Legacy:
As of ArcGIS Pro 3.6 and later, the arcpy.SetupDebugger function is no longer necessary for debugging. The arcpy.SetupDebugger function can still be inserted into scripts after import statements or in individual functions if breakpoints were not automatically detected. When finishing debugging, remove all calls to arcpy.SetupDebugger.
Microsoft Visual Studio Code
The following ArcGIS Pro components can be debugged in Visual Studio Code using the ArcGIS Pro Debugger Extension for Visual Studio Code:
Script tool code (source, validation)
Python toolboxes code (source, validation)
To get started with debugging script tools in Visual Studio Code, follow the link to install and read the documentation for the ArcGIS Pro Debugger Extension for Visual Studio Code. To report bugs or suggest enhancements for the extension, please log an issue in the Esri/arcgispro-vscode-debugger GitHub repository.
To install the extension from a PowerShell or terminal session, run the following command: code --install-extension esri-arcgis-pro.arcgis-pro-debugger.
Microsoft Visual Studio
The following ArcGIS Pro components can be debugged in Visual Studio:
Script tool code (source, validation)
Python toolboxes code (source, validation)
Learn more about debugging script tools with Visual Studio
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)
Learn more about remote debugging with PyCharm
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.