This is more of a reminder for me than a full-blown tutorial. It’s essentially the bullet point list of how to get a basic debug environment going, along with some philosophical musings on my part.
- Install Eclipse
- Install PyDev
- Start the PyDev debug server
- Create a new text block in Blender
- Paste this (suitably edited) at the beginning of the script:
PYDEV_SOURCE_DIR ='/home/dani/.eclipse/org.eclipse.platform_3.8_155965261/plugins/org.python.pydev_188.8.131.523090511/pysrc' import sys if sys.path.count(PYDEV_SOURCE_DIR) < 1: sys.path.append(PYDEV_SOURCE_DIR) import pydevd pydevd.settrace() bling = "the parrot has ceased to be" print(bling)
- Run the script in Blender – at this point Blender should hang
- Switch to Eclipse
- The file you are debugging should be open, with the line it has stopped at highlighted
Now, it’s possible that none of that happens with you. For some reason it ages for me to get all of this working.
So how does all this magic work?
When the Debug Server is started in Eclipse, it sits and listen on port 5678 on the loopback interface (methinks) for Blender to start sending it messages via the network stack. When this happens, Eclipse grabs then and does all the debugging stuff by communicating back and forth with Blender.
The script actually runs in Blender, but the debugging takes place in Eclipse, with Eclipse getting all the necessary information to do this by sending and receiving messages from Blender.
So, Eclipse if fully equipped to do the debugging at its end. Blender, on the other hand, needs a little help. First it needs to know where all the PyDev debugging stuff lives, because this will tell Blender how to communicate with Eclipse. You can Google the path for your specific platform, and in my case since I use Ubuntu I simply searched for “pysrc” thusly:
find /home/dani -iname pysrc
and on my computer I get this path:
Now it’s a matter of adding this path to the system path with:
import sys if sys.path.count(PYDEV_SOURCE_DIR) < 1: sys.path.append(PYDEV_SOURCE_DIR)
Now the system knows what to do when it gets this request:
It will hunt around for pydevd in the PYDEV_SOURCE_DIR and then import it.
Now when the script calls:
it will use pydevd to use the magic of the loopback interface and send and receive the messages to and from Eclipse to do its magic.
- Before debugging in Eclipse, change the perspective to Debug.
- Don’t try setting breakpoints in Eclipse. Do that in Blender using pydevd.settrace()
- Make sure the PyDev remote debugger is started before firing up Blender
- Automatic updates of PyDev creates a new folder for the PyDev python code among other things, so you will have to update your PYDEV_SOURCE_DIR path in your script