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

相关推荐
2401_838472511 小时前
使用Python进行图像识别:CNN卷积神经网络实战
jvm·数据库·python
CoLiuRs1 小时前
语义搜索系统原理与实现
redis·python·向量·es
摇滚侠1 小时前
IDEA 定义返回值快捷键
java·ide·intellij-idea
zhihuaba1 小时前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python
u0109272711 小时前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
Stream_Silver2 小时前
【Agent学习笔记3:使用Python开发简单MCP服务】
笔记·python
穿过锁扣的风2 小时前
零基础入门 Python 爬虫:从基础到实战,爬取虎扑 / 豆瓣 / 图片全掌握
开发语言·爬虫·python
Stream_Silver2 小时前
【Agent学习笔记2:深入理解Function Calling技术:从原理到实践】
笔记·python
love530love2 小时前
技术复盘:llama-cpp-python CUDA 编译实战 (Windows)
人工智能·windows·python·llama·aitechlab·cpp-python·cuda版本
逄逄不是胖胖3 小时前
《动手学深度学习》-60translate实现
人工智能·python·深度学习