简体   繁体   中英

debug Blender Python in Eclipse and PyDev?

How do you go about debug Blender Python in Eclipse and PyDev?

What I have tried is:

http://www.luxrender.net/wiki/LuxBlend25_Debugging_with_eclipse

http://www.blender.org/forum/viewtopic.php?t=3914&sid=717a127d12596f89e4aea0c54938ef80

But non of then seams to work?

Regards

There is very good e-book written by Witold Jaworski about Blender add-on programming. It includes chapters with step by step instructions how to setup Eclipce with PyDev to debug Blender add-ons. Programming Add-ons for Blender 2.5

Here is how I setup debug, which is slight different but based on the lux-render tutorial.

First, create the a .py file, lets call it debug.py, which will contain a function which we will call later to setup debugging. Put this file in the same folder as the main __init__.py of your module. As per the lux-renderer tutorial, add the following code, updating PYDEV_SOURCE_DIR.

import sys

def startdebug():
    try:
        # set the PYDEV_SOURCE_DIR correctly before using the debugger
        PYDEV_SOURCE_DIR = 'C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc'

        # test if PYDEV_SOURCE_DIR already in sys.path, otherwise append it
        if sys.path.count(PYDEV_SOURCE_DIR) < 1:
            sys.path.append(PYDEV_SOURCE_DIR)

        # import pydevd module
        import pydevd

        # set debugging enabled
        pydevd.settrace(None, True, True, 5678, False, False)
    except:
        pass

When setting the PYDEV_SOURCE_DIR ensure you point it to the org.python.pydev.debug_xxxxx. There is another folder similiar to this. To ensure you have the correct folder it will contain a /pysrc folder.

Now in your main __init__.py , this must come before any other import statements to work correctly. Add the following directly under the bl_info section, as strangely blender parses this itself.

DEBUGGING = True
if(DEBUGGING):
    import debug
    debug.startdebug()

Having it here will avoids adding per file traces like the lux-render tutorial.

  1. Add some breakpoint to the version in the add-ons folder,
  2. Switch to the debug perspective,
  3. Start Eclipses debug server,
  4. Start blender
  5. Run the script and it will hit the breakpoint.

The common problems I find people encounter:

  • pointing the path to the wrong pydev debug folder, ensure that there is a /pysrc folder
  • When Pydev updates, update the PYDEV_SOURCE_DIR as the debug_xxxxx will have change
  • not having eclipse server running,
  • setting breakpoints on a local copy of the files instead of the version in the blender add-on directory
  • saving the script does not mean that blender will reload it, use imp, disable/renable the add-on or restart Blender.

There are quite comprehensive instructions for setting up blender and eclipse for debugging. http://wiki.blender.org/index.php/User:Z0r/PyDevAndProfiling

While this is for blenders game engine, much of it applies to regular blender.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM