VScode debug python(服务器)

方法一:

创建launch.json文件:

launch.json文件地址:

launch.json文件内容:

bash 复制代码
{
    
    "version": "0.2.0", //指定了配置文件的版本
    "configurations": [
        {
            "name": "Python: Current File", //指定了这个配置的名称,显示在 Visual Studio Code 的调试器界面中
            "type": "python", // 指定了调试器的类型,这里是 Python 调试器
            "request": "launch", // 指定了调试请求的类型,这里是 "launch",表示启动调试
            "program": "${file}", // 指定了要调试的程序的入口文件,这里使用了 ${file} 变量,表示当前打开的文件。
            "console": "integratedTerminal", // 指定了调试器的输出控制台类型,在集成终端中输出。
            "justMyCode": true, // 指定了是否只调试用户自己的代码,而不调试第三方库的代码,这里设置为 true。
            "cwd": "/home/usr/MultiCapCLIP-master" // (项目的路径)指定了当前工作目录,即程序的执行路径
            "args":[
                "--pickle", //action参数
                "--dataset","msrvtt",
                "--method","baseline"
                ] // 终端传入参数
        }
    ]
}

注意,"cmd"写自己项目地址,否则会出现以下问题,找不到文件。

bash 复制代码
"cwd": "/home/usr/drq/MultiCapCLIP-master" // (项目的路径)指定了当前工作目录,即程序的执行路径

"name"是json配置名字,可以在这里看到:

bash 复制代码
"name": "Python: Current File", //指定了这个配置的名称,显示在 Visual Studio Code 的调试器界面中

接下来打断点,可以debug:

方法二:

另外一个版本launch.json文件:

bash 复制代码
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 远程调试",
            "type": "python",
            "request": "attach",
            "listen": {
                "host": "0.0.0.0",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}", 
                    "remoteRoot": "."
                }
            ],
            "cwd": "/home/usr/MultiCapCLIP-master",
            "args":[]

        }
    ]
}

需要在.py文件头加入:

python 复制代码
import debugpy; debugpy.connect(('ip地址', 5678))

例如:

相关推荐
敏编程36 分钟前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪43 分钟前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook1 小时前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田14 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪17 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽18 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战18 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋1 天前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者2 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者2 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python