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相对导入常见问题和解决方案

相关推荐
TF男孩6 小时前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
该用户已不存在11 小时前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP13 小时前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
用户83562907805118 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
c8i18 小时前
python中类的基本结构、特殊属性于MRO理解
python
liwulin050619 小时前
【ESP32-CAM】HELLO WORLD
python
Doris_202319 小时前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_202319 小时前
Python 模式匹配match case
前端·后端·python
这里有鱼汤20 小时前
Python量化实盘踩坑指南:分钟K线没处理好,小心直接亏钱!
后端·python·程序员
大模型真好玩20 小时前
深入浅出LangGraph AI Agent智能体开发教程(五)—LangGraph 数据分析助手智能体项目实战
人工智能·python·mcp