Debugging in Maya with debugpy and VSCode
Debugging your python code in Maya is particularly painful subject, for sure.
Proper debugging. With a debugger…
I’ve tried many times and gave up. Setting it all up and making it work is just way too much of a hassle. I know some people have made it work with pycharm but
- a) I dont use pycharm and
- b) I still think there are some issues there (more info here, here, and here).
This post is about vscode and for a long time a “go to” debugger was ptvsd. Here are quick instructions how to use it to debug python in maya: link and link.
However, Microsoft has since deprecated ptvsd in favor of debugpy. The way to use it is pretty much the same with minor difference in code that needs to be run so here it is (replicating Joseph Yu’s steps for comparison):
- Download and install Visual Studio Code
- Install the official Python Extension
- Grab the latest release of debugpy as a zip
- Extract
scr/debugpy
intodocuments/maya/scripts/debugpy
- Open Maya and run:
import os import debugpy mayapy_exe = os.path.join(os.environ.get("MAYA_LOCATION"), "bin", "mayapy") debugpy.configure(python=mayapy_exe) debugpy.listen(5678)
- Open your project in vscode and create
launch.json
(you can do this manually really): - Open
.vscode/launch.json
and replace the default content with:{ "version": "0.2.0", "configurations": [ { "name": "Python Attach", "type": "python", "request": "attach", "port": 5678, "host": "127.0.0.1", } ] }
- Click
Start Debugging
:
You may now place your breakpoints and call the code from Maya.