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))

例如:

相关推荐
两万五千个小时2 小时前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿5 小时前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户83562907805119 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng821 小时前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi21 小时前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee21 小时前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay1 天前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤1 天前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean1 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
曲幽1 天前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi