Blenderproc: any suggestion how we can debug with pycharm?

Created on 7 Feb 2020  路  9Comments  路  Source: DLR-RM/BlenderProc

Hi,
I would ask if you can provide some useful practical suggestion on how to debug the code (since in the main run.py, you use Popen to start a new thread), especially if with pycharm.

Some references links would be great

Thanks

All 9 comments

Great question, so far we only used Blender itself to debug code, we have not used an actual debugger (with breakpoints, ...), yet. Luckily, we have never needed one so far.

My biggest fear, with using an actual debugger is that you will have problems seeing what state blender currently has, a lot of the variables are static. For that we recommend using the debugging example. There you can run your module inside of blender and see what happens directly in the viewer.

If you find a way of jumping right into the python process with Pycharm, we would be happy if you share it with us.

If you need help with something, you can just ask of course, we might be able to help you.

Thanks for quick reply, I will explore how to debug. It will be helpful to understand the code.

find a way works. https://github.com/microsoft/ptvsd
add the snippet in somewhere src/run.py

import ptvsd
ptvsd.enable_attach()
ptvsd.wait_for_attach()  # blocks execution until debugger is attached

then start a debug client in vscode will work with below configuration

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        },
    ]
}

Hopefully this will be helpful.

Thanks for the contribution, we will add this to the debugging example.

Hi everyone, first of all thanks for this great repository!

By using a Python Debug Server configuration in Pycharm I was able to locally debug the code which is running on a remote machine.
I followed this tutorial: https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html?_ga=2.146690868.1490170423.1595358878-1470810880.1594648728#remote-debug-config

As the tutorial says,

  1. Configure a Debug Server in PyCharm
  2. Install the correct pydevd_pycharm package on the remote machine with the pip of python that comes with blender
  3. Run the Debug Server within PyCharm
  4. Add
    import pydevd_pycharm
    pydevd_pycharm.settrace('<ip of local machine>', port=<configured port>, stdoutToServer=True, stderrToServer=True)
    to your src/run.py file
  5. Execute src/run.py on the remote machine
  6. Debug within PyCharm

Hope that helps 馃槂

Thanks for this great remark @xheon!

One thing regarding step 2, this can easily be done via the config.

https://github.com/DLR-RM/BlenderProc/blob/0a5da9b3294d9e5c169d6b189442d13ed84a173f/examples/basic/config.yaml#L6-L8

Just add the package you want to install there, it will be installed as soon as the config is run. After that, packages stay as long as they are not directly removed or until a new blender version comes out.

Ah nice!

This addon might be relevant. I haven't tested it myself yet though.

Thanks for this great remark @xheon!

One thing regarding step 2, this can easily be done via the config.

https://github.com/DLR-RM/BlenderProc/blob/0a5da9b3294d9e5c169d6b189442d13ed84a173f/examples/basic/config.yaml#L6-L8

Just add the package you want to install there, it will be installed as soon as the config is run. After that, packages stay as long as they are not directly removed or until a new blender version comes out.

Note: I tried this but I got that "pydevd_pycharm" was not found during import.

I then installed id directly using blender's pip and it worked.

This may be something that I was doing wrong, but just for reference as an alternative in case some oneelse encounters it.

Was this page helpful?
0 / 5 - 0 ratings