I just thought I’d share my setup that I use for debugging Toolkit code. Note that I’m using the paid version of PyCharm in order to do this. I believe it should be possible with Visual Studio Code as well, and I may add details on that later if I can get it working.
Why use a debugger?
Using a debugger can be extremely useful, as you can do all sorts of things like
- Add breakpoints in your code.
- Pause and step through the live execution
- Read variable values as you go.
If you’re running your code through an IDE, then you can usually make use of the IDE’s debugger, however, it’s not so easy to debug your code when you need to run it in a DCC such as Maya or Nuke. That’s where remote debugging can come in. Typically this is used when you want to debug code that is running on another computer, but we can also use it to debug code that is running in a different process.
Please note that this isn’t something that Shotgun directly supports, I’ve added it here as a hopefully useful suggestion.
Setting it up
How you approach remote debugging will depend entirely on what IDE you’re using, and some may not support it at all. You should check out your IDE’s documentation to find out what’s possible.
Here is an example of how to get this up and running with PyCharm.
Make sure that you’re working in a sandbox configuration and that the code for the app, engine, or framework you want to debug is local to your machine.
Open up the same app code in an existing project or as a new project in PyCharm.
In PyCharm you can set up Python Remote Debug just like in their documentation, however, rather than pointing at a different machine, you can point at
Now you can start up the debugger:
Run the following code in your software to connect to the remote debugger. Note the path to the pydevd module maybe different on your machine:
import sys sys.path.append("/Applications/PyCharm.app/Contents/debug-eggs/pydevd-pycharm.egg") import pydevd pydevd.settrace('localhost', port=1234, stdoutToServer=True, stderrToServer=True)
The above code can either be inserted into your Hook or App, or you can run it separately in your software’s Python editor once it’s launched.
Once you’ve run the above code, the Software will likely freeze until you resume from PyCharm. Now all that is left to do is to add your breakpoints to your code and start debugging.