Connect VSCode Debugger to Maya

Debug Python scripts in Maya using VSCode and debugpy

VSCodeMaya

1. Install debugpy in Maya

Run this script inside maya to install debugpy package.

import subprocess, sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "debugpy"])

2. Create .vscode/launch.json

In the debug and run tab inside VSCode select the option to create a launch.json file, this will create a .vscode folder in your project and inside the launch.json file you can add this configuration.
You can add more configurations if you need to be able to connect to multiple mayas.

{
    "version": "0.2.0",
    "configurations": [{
        "name": "Attach to Maya",
        "type": "python",
        "request": "attach",
        "connect": { 
            "host": "localhost", 
            "port": 5678 
            }
    }]
}

3. Open a debugpy port in Maya

import debugpy
debugpy.listen(("localhost", 5678))

4. Attach VSCode

Press F5 or go to Run and debug and press the play button in VSCode with your script open. Set breakpoints and debug.

Cookies

I use Google Analytics to collect anonymous data on website interactions.
This helps me to identify popular content and create more of what you like.