PyDev has debugger:
Turns out Pydev has a nice plugin/package calling the module pydevd.py. Instructions on generic usage are here:
When we say remote, it doesn’t have to be on another computer, it can be on your own computer, it is just debugging a script that is not being run from within your Eclipse Development Environment, but is being executed from some other source like a Python IDLE console or a DCC app running Python, like Maya! So let’s do it . . .
Firstly, you’ll need the path to the pydevd.py module in your Maya session’s pythonpaths. Follow the instructions in the link above to find out where this path is (something like: eclipse/plugins/org.python.pydev.debug_x.x.x/pysrc/). Add it to your python path in via Maya.env, userSetup.mel, userSetup.py, or your preferred method. Restart Maya of course.
Start Pydev server:
Now you actually need to start the server per the link’s instructions by first switching to your debug perspective, ‘cause that’s what it’s for and then pressing the little bug icon in your toolbar to start the Pydev server.
Load module, call method:
You can now add these lines to the script you want to debug:
# basic start trace import pydevd pydevd.settrace()
Probably want to echo to Eclipse w/ these args:
# echo stdout and errors to Eclipse pydevd.settrace(stdoutToServer=True, stderrToServer=True, suspend=False)
If you run the script with this line in Maya when your Eclipse Pydev server is running, Eclipse will grab the process at this line. But what is nicer is to just establish the connection and set your breakpoint in any script in Eclipse and then Eclipse will grab the process as soon as you run that script in Maya. You’ll need to modify the suspend=True arg to False so suspension does not happen at the spot this line is run, but instead just makes the connection and waits for suspension to happen when a breakpoint is hit:
# just put this at the top of any script import pydevd pydevd.settrace(stdoutToServer=True, stderrToServer=True, suspend=False)
Set your breakpoint in your python script. Call it from Maya, Maya will hang, switch to Eclipse and look for the magic green line.
Now you get awesome stack data, listed as “Variables” in Eclipse and the Console is interactive! just like the debug probe in Wing. Don’t forget that Eclipse can ‘watch’ variables with the “Expressions” window too! If you don’t think this is awesome, you are not a serious Maya Python programmer, ‘cause this is the coolest thing since sliced bread if you ask me.
Eventually you’ll probably want to just make a command like this:
# better yet, make little method def connectToEclipse(): import pydevd pydevd.settrace(stdoutToServer=True, stderrToServer=True, suspend=False)
And just call the function whenever your gonna start your debugging.
One Thing Missing:
There is one major convenience missing in this “debug probe” however, and that is code-completion. One of the huge advantages of the Debug Probe in Wing IDE while you’re debugging Maya is that you can “see” what the current environment is inside Maya at any given moment. This is so handy it is hard to describe. Very handy for diagnosing why certain Python packages and modules are not importing so well. With Wing’s Debug Probe, you just interrupt your session, and start typing “import” and you can start to experiment with paths and namespaces to see what will import under what name. Anyway, I miss the code-completion in this Console.
Of course the connections can get a little sticky and you may have to restart one or both apps occasionally to get things setup again. Just FYI.
Regardless, this connection is awesome; so infinitely valuable to debug in real-time, I won’t even start. Wing does it a little more nicely, but it does cost. Great thing about Eclipse and Pydev, is that it is free!