VSCode远程调试python

配置

1,进入到服务器相应的docker和conda环境中

2,安装debugpy pip install debugpy

3,VSCode 中点击调试按钮

4,按照提示,安装扩展

5,配置launch.json


最终的文件launch.json:

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,终端运行

shell 复制代码
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

目录结构如下:

shell 复制代码
|- peft
	|- src
		|- test.py
		|- peft
			|- __init__.py
			|- ...

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

相关推荐
SEO_juper21 分钟前
Node.js 重定向链检测工具:301 跳了几跳、有没有成环,一次看清
xml·开发语言·python·node.js·json·bash
曲径海盗27 分钟前
【Python 学习第 37 天】for 循环
python·学习笔记·编程入门
心静财富之门1 小时前
Python 数据共享四种方案完整实例(同进程 / JSON / Redis / HTTP)
数据库·python·oracle
golang学习记1 小时前
Zed Git重大更新:目录级对比支持分栏Diff
git·vscode·zed
王仔小奶1 小时前
慢SQL治理与性能调优:DBA如何用Shell/Python提升运维效率?
python·sql·dba
用户0332126663671 小时前
使用 Python 快速在 PowerPoint 中生成表格【教程】
python
夜晚回家2 小时前
Python 身份运算符详解 | is 与 == 到底差在哪
python
fengye2071612 小时前
cpython框架结构
python
用户91294046848422 小时前
大模型返回 JSON 后,先过这道 Python 校验
python
Dmz丶2 小时前
前端转 AI 100 天 Day 32:LLM 客户端工程化——重试、超时、降级、限流
python