Select to view content in your preferred language

Debugging a Python Toolbox using Visual Studio Code

2743
8
07-16-2021 04:55 PM
Brian_Wilson
Honored Contributor

I found the docs on using Visual Studio and PyCharm but I wonder if anyone has had success with Visual Studio Code?

I set up launch.json and I can attach to ArcGISPro.exe but I am not sure what comes after that. I can set breakpoints in my .py file from the IDE but they are never hit.

I use F5 to run and wait for the status bar to go orange which indicates it's running. I must be very close, because I can see print() statement output in the IDE's Debug Console window.

BrianWilson7_1-1626479346321.png

I am running ArcGIS Pro 2.8 on Windows 10 using the newest VS Code.

If you are interested in seeing the Python code, it's here

https://github.com/Wildsong/ArcGIS_Python_Template

 

My launch.json looks like this

{
  "version": "0.2.0",  "configurations": [
    {
      "name": "Python: Attach using Process Id",
      "type": "python",
      "request": "attach",
      "processId": "${command:pickProcess}"
    },
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ]
}

Happy Friday!

8 Replies
ErickPoundFDNY
Emerging Contributor

Hi Brian,

Did you ever find a resolution to this? I'm in the same boat currently. Thanks.

OrrGvili
Occasional Contributor

what worked for me

1. run ArcGIS pro (3.0)

2. open vs code with the script open 

3. in vs code  run and Debug , then select  attach using process ID 

and select the ArcGIS pro processed

run the gp tool in  ArcGIS pro  

 

 

0 Kudos
ErickPoundFDNY
Emerging Contributor

Doesn't seem to work for me. It seems to attach but it runs in AGP without hitting the breakpoints.

I tried a couple different routes:

1. Debug on the tool script

2. Debug on the toolbox (pyt)

3. Removing and re-adding the toolbox.

I get the debug pane in VS (variables, call stack, etc) but no breakpoints. How is your toolbox laid out?

0 Kudos
OrrGvili
Occasional Contributor

since the move to arcPro 3 
its not working as expected 

0 Kudos
Stefan_Schlaefli
New Contributor

For me it does work with debugpy breakpoints but not with visualstudio breakpoints. For using debugpy import debugpy in your python tool file (.pyt) :

import debugpy

 

on those lines where you want the debugger to stop, call debugpy's breakpoint() method: 

debugpy.breakpoint()

 

Then run and debug add a debug configuration that let's you pickup the Process ID of the running ArcGIS Pro application: 

 {
            "name": "Python: Attach using Process Id",
            "type": "python",
            "request": "attach",
            "processId": "${command:pickProcess}",
            "justMyCode": true
 }

Start debugging, wait for the debugger to connect and then run the Python Tool in ArcGIS Pro. The debugger will stop wherever the debugpy.breakpoint() call was set. 

0 Kudos
ErickPoundFDNY
Emerging Contributor

I have taken to running the tools outside AGP entirely. It has sped up development by sidestepping the 'reload toolbox' requirement. That said, I would still like to get this going if anyone finally cracks this.

0 Kudos
AndyDixon
Emerging Contributor

I've just come across this post after searching for the solution for a while, this was the closest I got as well. I can see print commands but can't see any of the variables or watched expressions. Anyone managed to get this working in the last year?

0 Kudos
AndresCastillo
MVP Regular Contributor
0 Kudos