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 pc_debug_toolbar or the File menu >> Run >> Edit Configurations.

pc_debug_config

The default settings are okay with the following exceptions:

  1. 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.
  2. 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

  1. Fire up the remote debugger in PyCharm, first
  2. Connect Mobu via running the statement PyCharm instructs…
    >>> import pydevd
    >>> pydevd.settrace('localhost', port=9999, stdoutToServer=True, stderrToServer=True)

Stop

  1. In Mobu:
    >>> pydevd.stoptrace()
  2. 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