VSCode远程调试python

配置

1,进入到服务器相应的docker和conda环境中
2,安装debugpy pip install debugpy
3,VSCode 中点击调试按钮
在这里插入图片描述
4,按照提示,安装扩展
在这里插入图片描述
5,配置launch.json
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
最终的文件launch.json

{
    
    
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "Python: 远程附加",
            "type": "python",
            "request": "attach",
            "connect": {
    
    
                "host": "0.0.0.0",
                "port": 5678
            },
            "pathMappings": [
                {
    
    
                    "localRoot": "/xxx/peft/src", // test.py文件目录
                    "remoteRoot": "."
                }
            ],
            "justMyCode": true
        }
    ]
}

调试

6,终端运行

python -m debugpy --listen 0.0.0.0:5678 --wait-for-client test.py

7,设置断点,点击运行按钮,即可debug
在这里插入图片描述
在这里插入图片描述

问题

1,我要调试peft相关代码,test.py脚本不要放到peft目录中,因为peft代码用了相对路径import,会报错:ImportError: attempted relative import with no known parent package
目录结构如下:

|- peft
	|- src
		|- test.py
		|- peft
			|- __init__.py
			|- ...

知乎:python相对导入常见问题和解决方案

猜你喜欢

转载自blog.csdn.net/dragonchow123/article/details/132742197