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

例如:

相关推荐
ponponon23 分钟前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly24 分钟前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程37 分钟前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly2 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
明月_清风9 小时前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风9 小时前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
ZhengEnCi1 天前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风1 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风1 天前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
Flittly2 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent