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

相关推荐
Zzzz_my5 分钟前
正则表达式(RE)
pytorch·python·正则表达式
天天鸭33 分钟前
前端仔写了个 AI Agent,才发现大模型只干了 10% 的活
前端·python·ai编程
setmoon2141 小时前
使用Scikit-learn构建你的第一个机器学习模型
jvm·数据库·python
2401_833197731 小时前
为你的Python脚本添加图形界面(GUI)
jvm·数据库·python
敏编程2 小时前
一天一个Python库:tomlkit - 轻松解析和操作TOML配置
python
2401_879693872 小时前
使用Python进行图像识别:CNN卷积神经网络实战
jvm·数据库·python
bandaostart2 小时前
VsCode+Cmake使用说明
ide·vscode·编辑器
yunyun321232 小时前
机器学习模型部署:将模型转化为Web API
jvm·数据库·python
freshman_y2 小时前
个人VSCode一些配置记录
ide·vscode·编辑器
码农诗人2 小时前
AI代码生成插件continue用vscode源码编译步骤
vscode·continue·源码编译