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

例如:

相关推荐
aqi0018 分钟前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵2 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf3 小时前
Agent 流程编排
后端·python·agent
copyer_xyf3 小时前
Agent RAG
后端·python·agent
copyer_xyf3 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf4 小时前
Agent 记忆管理
后端·python·agent
星云穿梭19 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵19 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏
黄忠1 天前
大模型之LangGraph技术体系
python·llm