Debugging Motion Builder Scripts in PyCharm (3.4)
So, you want debug python in MoBu with PyCharm but either aren’t sure how to set it up or missed some detail along the way. Well, this post should help.
Note: Much of this information holds true for Maya and other applications with integrated python.
Setup
PyCharm
Official Documentation: http://www.jetbrains.com/pycharm/webhelp/remote-debugging.html
Basically, you need to setup a Remote_Debugger. Either via the Toolbar drop_down_list next to the Run Icon or the File menu >> Run >> Edit Configurations.
The default settings are okay with the following exceptions:
- Lock down a port by specifying one you know to be open. This helps avoid you needing to enter a new port number in MoBu every time you start the debugger and connect to it.
- I typically Uncheck the “Suspend after Connect”…I’m normally only interested in suspending at breakpoints or exceptions.
Mobu
What you need is to be able to load a version of pydevd that is compatible with your Mobu’s version of python. This is included with PyCharm, within the .egg files at the root of PyCharm’s installation directory.
For example, in Mobu:
# *** SETUP *** import sys PYCHARM_EGG_PATH = r"C:\Program Files (x86)\JetBrains\PyCharm 3.4.1\pycharm-debug.egg" if not PYCHARM_EGG_PATH in sys.path: sys.path.append( PYCHARM_EGG_PATH ) import pydevd # *** Connect to debugger *** pydevd.settrace('localhost', port=9999, stdoutToServer=True, stderrToServer=True)
Execution
Start
- Fire up the remote debugger in PyCharm, first
- Connect Mobu via running the statement PyCharm instructs…
>>> import pydevd >>> pydevd.settrace('localhost', port=9999, stdoutToServer=True, stderrToServer=True)
Stop
- In Mobu:
>>> pydevd.stoptrace()
- In PyCharm, stop or restart the debugger
Note: Do not stop this without disconnecting MotionBuilder first.
Bonus
- For static auto-completion in PyCharm, add the following to your PyCharm’s Project’s PYTHONPATH
"C:\Program Files\Autodesk\MotionBuilder 2015\bin\config\Python\pyfbsdk_gen_doc.py"
- I typically rename it and import it per the following in every script. Mobu uses its local pyfbsdk and PyCharm uses the stub for autocomplete:
>>> import pyfbsdk
about 5 years ago
I just switched to PyCharm and love it. Thanks for this tutorial. One question though: Could you please explain for dummies how to do configure PyCharm to get the bonus of pyfbsdk_gen_doc autocompletion? I tried by going to Settings: Project Interpreter -> gear symbol: more -> Show paths for selected interpreter -> Add: C:\Program Files\Autodesk\MotionBuilder 2017\bin\config\Python\
I can see it in a list when typing import pyfb etc., but trying to import gives me this error:
File “C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py”, line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named pyfbsdk
about 5 years ago
Oh, never mind. I tried importing it in the console, but using a scratch file and doing ‘from pyfbsdk import *’ just worked fine.