【maya插件开发】vscode debug python 代码

maya端

python 复制代码
import sys
import os
import debugpy


maya_location = "D:\\soft\\maya\\maya2022_4\\Maya2022\\bin\\mayapy.exe"
debugpy.configure({'python': maya_location})
try:
	debugpy.listen(5678)
except Exception as e:
	print("Port 5678 is already in use. Debugger might be already running.")
print("Waiting for debugger attach")
debugpy.wait_for_client()
debugpy.breakpoint()
print('break on this line')

vscode:launch.json

python 复制代码
{
    // 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 Debugger: Remote Attach",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                "localRoot": "${workspaceFolder}",
                "remoteRoot": "D:/soft/maya/maya2022_4/Maya2022/bin/plug-ins"
                }
            ]
        }
    ]
}
  1. 远程调试允许您暂停代码执行、检查变量值和查看函数调用返回,这对于排查Maya脚本中的复杂问题非常有用。

  2. 在Maya中设置远程调试的步骤:

  • 将debugpy模块添加到Maya的PYTHONPATH中

  • 使用代码片段初始化debugpy并等待调试器连接

  • 在VS Code中配置"Remote Attach"调试配置

  1. 设置调试时的一个关键问题是Maya返回自身的可执行文件路径,而不是Python解释器路径。这会破坏默认的debugpy配置。

  2. 解决方案是显式配置debugpy使用mayapy.exe解释器:

```python

maya_location = os.path.join(os.environ.get("MAYA_LOCATION"), "bin", "mayapy.exe")

debugpy.configure({'python': maya_location})

```

  1. 为了有效使用断点,应该在文件中编写脚本,然后通过Maya的脚本编辑器导入/调用它,而不是直接在编辑器中运行代码。

  2. VS Code中的Debug REPL功能允许您在调试会话期间在脚本的各行之间运行代码。

  3. 远程调试对于在使用复杂API(如PySide2或Maya的API)时检查对象和测试返回值特别有用。

这篇文章提供了在Maya中设置和排查远程调试问题的逐步指南,这可以显著改善Maya工具和脚本的开发和调试过程。

相关推荐
wuyk5557 分钟前
Python 第三章:列表 List
服务器·开发语言·python
笨鸟先飞,勤能补拙10 分钟前
从预测到决策:人工智能与机器学习的系统方法、工程闭环与现实边界
大数据·人工智能·windows·python·机器学习·密码学
MgArcher44 分钟前
抖音a_bogus参数逆向实战:JSVMP环境模拟与Hook技术(2025最新)
javascript·爬虫·python
circuitsosk1 小时前
AI输出的“质检员”:构建智能体质量评估、异常检测与人工兜底的三层防线
人工智能·python·microsoft·正则表达式·langchain
要努力点1 小时前
Python入门第六课
开发语言·python
CTA终结者2 小时前
先用小策略练清条件和动作
人工智能·python
Bruce_Liuxiaowei2 小时前
从零到可运行:基于 Vue3 + FastAPI + DeepSeek-V3 的 AI 英语单词学习系统全栈实战
人工智能·python·学习·fastapi·全栈·智能体
ValhallaCoder2 小时前
Leetcode-hot100(2026.08.17)
python·算法·leetcode
W_326002 小时前
Python-OpenCV图像像素与通道:通道拆分合并、深浅拷贝
图像处理·人工智能·python·opencv·机器学习
让你三行代码QAQ2 小时前
AI大模型开发核心名词速览
python