Debugging Maya using Visual Studio Code


I've been testing debugging Maya Python scripts lately. Mostly focusing on free IDEs or editors such as PyCharm. So far this is one requires less setup in my opinion.

This is mostly based off the remote python debugging functionality described here:
  1. Download and install Microsoft's free Visual Studio Code
  2. Install the official Python Extension 
  3. Extract the ptvsd folder into your Maya scripts folder
  4. Open Maya and run (updated! Thanks Luciana!)
    import ptvsd
    ptvsd.enable_attach(address=('0.0.0.0', 3000), redirect_output=True)
  5. Back in VSC, switch to Attach (remote debug) in the debug configurations and start it

    The editor should now look something like this
  6. You are now ready to debug. 
Note: here is the settings I use in launch.json



Add break points, run your code and it should stop and populate the debug section of Visual Studio code when it hits a break point

Comments

  1. My breakpoints are grey/ignored. Do you know of a way to fix this?

    ReplyDelete
  2. I think your break point is disabled, right-click on it and select "Enable Breakpoint"

    ReplyDelete
    Replies
    1. Hi Joe, thanks for your reply.
      No I don't think the breakpoint is disabled, it is coming up as unverified. Perhaps the connection process is not completing, I cannot see any output in the vs code window

      Delete
  3. Same for me, my break point are iognored, can you make a video about this.
    It could be really helpfull

    ReplyDelete
  4. What settings do you guys use for the launch.json?
    I've just updated the post with my settings, give them a go and let me know if it works

    ReplyDelete
  5. Hi,

    What you describe in your article seems really promising, but unfortunatly, I've got the same problem : my breakpoint are greyed out and it is written "Unverified Breakpoint".

    https://imgur.com/a/XltBC

    Here is my launch.json : https://imgur.com/a/O5L9C

    I'm using VSCode 1.16.0 and pythonVSCode 0.7.0.

    I tried to disable all my other plugins with both 32 and 64 bits versions of vscode but nothing worked.

    It seems that other people already had this problem as you can see on github https://github.com/DonJayamanne/pythonVSCode/issues/690 but there was no solution to it.

    Any ideas :/ ?

    ReplyDelete
    Replies
    1. I'm very late to the party here but others might stumble upon this page.

      The visual studio code Documentation states that you need ptvsd 3.0.0 and exactly this version.
      installing it worked perfectly for me!

      https://code.visualstudio.com/docs/python/debugging#_remote-debugging

      Delete
  6. Remote debugging no longer supports the 'secret' field (see here: https://github.com/Microsoft/vscode-docs/issues/1794). So step 5 should be edited to: ptvsd.enable_attach((address = ('0.0.0.0', 3000), redirect_output=True)

    ReplyDelete
  7. It might be a good idea to direct people to the downloads page for ptvsd and call out downloading the latest. I'm assuming VSCode updates to have the latest and the versions need to be the same. Initially I had trouble getting things working not realizing 3.0.0 wasn't the latest but nothing errored, it just didn't go into debug mode.

    ReplyDelete
  8. Hey Joe,

    I tried setting it up with Maya 2017 extension5, pvsd 4.2.10, vscode still can't hit the breakpoint.
    I'm getting all the std output, list of threads in call stack, but when I type "import maya" I get

    import maya
    Unable to find thread for evaluation.

    Anyone knows how to deal with this?

    Cheers,
    kk

    ReplyDelete

Post a Comment

Popular posts from this blog

More nParticle Butterfly Tests

Vray Non-Photorealistic shading Splur