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

相关推荐
醒过来摸鱼1 小时前
Java classloader
java·开发语言·python
superman超哥1 小时前
仓颉语言中元组的使用:深度剖析与工程实践
c语言·开发语言·c++·python·仓颉
小鸡吃米…1 小时前
Python - 继承
开发语言·python
祁思妙想1 小时前
Python中的FastAPI框架的设计特点和性能优势
开发语言·python·fastapi
Dingdangcat862 小时前
反恐精英角色识别与定位-基于改进的boxinst_r101_fpn_ms-90k_coco模型实现
python
世界唯一最大变量2 小时前
利用自定义积分公式,目前可以求出所有1元方程和1元积分的近似值
python
写代码的【黑咖啡】2 小时前
深入理解 Python 中的模块(Module)
开发语言·python
爱笑的眼睛113 小时前
超越 `cross_val_score`:深度解析Scikit-learn交叉验证API的架构、技巧与陷阱
java·人工智能·python·ai
smj2302_796826524 小时前
解决leetcode第3782题交替删除操作后最后剩下的整数
python·算法·leetcode
gCode Teacher 格码致知5 小时前
Python基础教学:Python 3中的字符串在解释运行时的内存编码表示-由Deepseek产生
python·内存编码