-
Notifications
You must be signed in to change notification settings - Fork 26
Debugging (Development)
There are two types of scripts, the ones that are under the mmvt_addon folder, which are running inside Blender, and the rest.
For the ones that are running in Blender, you need to set first a remote debug server in pycharm:
Then, you need to install the debug addon in Blender. You can find it in the mmvt_code folder, in resources/addons/remote_debugger.py
In Blender, go to File -> User Preferences. Open the Add-ons tab, and click on "Install add-on from File". Choose the remote_debugger.py file, and click on install. You should also set the path of the pycharm-debug-py3k.egg file the is located in your-pycharm-folder/debug-eggs.
Now, in PyCharm choose the remote debugger, and click on the debug button (that looks like a green bug...):
Now you can click in Blender on space, write debug, and choose "Connect to remote...":
The code will stop in Pycharm in the remote_debugger.py file:
Click on "Resume Program" (F9). Now you can add a breaking point in the line you want to debug, do whatever GUI command that activates this code, and voila.
For scripts run from the command line, python -m src.setup for instance, there is no remote debugger necessary. However, there are some configuration steps to get the debugger to run.
First, configure the python interpreter in settings. In MacOS this is under PyCharm >> Preferences >> Project Interpreter, in Linux and Windows (?) this is under File >> Settings >> Project Interpreter. Click the settings wheel to the right of the interpreter path, then choose whether you want to use a virtual environment, a conda environment or a system interpreter (recommended because it's the easiest and when you ran src.setup you installed all the necessary packages (NB if your local python is older than 3.5, your blender python interpreter was used instead to install prerequisite packages /path/to/blender/Blender/blender.app/Contents/Resources/2.79/python/bin/python3.5m for example).
Set the interpreter to be pointed at your installation of python that you want to use. If you skip this step, the error will be that the default interpreter will not have any of the modules installed that you will need to run your project, i.e. ModuleNotFoundError: No module named 'tqdm'. Make sure to select your interpreter and press apply and optionally delete the default interpreter. NB after selecting a new interpreter, PyCharm will have to load your libraries which may take some time (the status should be indicated in the lower right corner), in the interim, all the options related to running will be greyed out.
Next, configure a debugging script with any name you choose, the module name (e.g. src.preproc.anatomy), the module parameters (e.g. -s me --remote_subject_dir /path/to/my/recon/folder/me), and the python interpreter set to project default (important! this is the one you just configured).
Now you should be able to debug like most other setups; click to the left of the line to set a break point and use the buttons at the bottom to move through your script.