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

maya端 

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

{
    // 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"调试配置

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

4. 解决方案是显式配置debugpy使用mayapy.exe解释器:
   ```python
   maya_location = os.path.join(os.environ.get("MAYA_LOCATION"), "bin", "mayapy.exe")
   debugpy.configure({'python': maya_location})
   ```

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

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

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

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

相关推荐

  1. maya开发】vscode debug python 代码

    2024-07-10 12:16:02       10 阅读
  2. Wireshark开发

    2024-07-10 12:16:02       36 阅读
  3. blender开发

    2024-07-10 12:16:02       46 阅读
  4. vscode:开发

    2024-07-10 12:16:02       24 阅读
  5. Chrome开发

    2024-07-10 12:16:02       17 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 12:16:02       4 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 12:16:02       5 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 12:16:02       4 阅读
  4. Python语言-面向对象

    2024-07-10 12:16:02       5 阅读

热门阅读

  1. 【AI应用探讨】—主成分分析(PCA)应用场景

    2024-07-10 12:16:02       11 阅读
  2. 基数排序算法Python实现

    2024-07-10 12:16:02       9 阅读
  3. qt todoapp

    2024-07-10 12:16:02       8 阅读
  4. 如何减少开发过程中的bug-数据库篇

    2024-07-10 12:16:02       9 阅读
  5. 驻场运维的前途在哪里,这里有金玉良言

    2024-07-10 12:16:02       9 阅读
  6. 认字之 刬

    2024-07-10 12:16:02       7 阅读
  7. lvs集群

    lvs集群

    2024-07-10 12:16:02      9 阅读
  8. AUTOSAR:汽车软件架构的未来

    2024-07-10 12:16:02       9 阅读
  9. 相机光学(二十九)——显色指数(Ra)

    2024-07-10 12:16:02       9 阅读
  10. 贪心算法合集一

    2024-07-10 12:16:02       8 阅读
  11. 索引知识总结

    2024-07-10 12:16:02       10 阅读