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

例如:

相关推荐
千寻girling几秒前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook4 小时前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风5 小时前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风5 小时前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei21 小时前
python 抽象基类
python
用户83562907805121 小时前
Python 实现 PPT 转 HTML
后端·python
zone77391 天前
004:RAG 入门-LangChain读取PDF
后端·python·面试
zone77391 天前
005:RAG 入门-LangChain读取表格数据
后端·python·agent
树獭非懒2 天前
AI大模型小白手册|Embedding 与向量数据库
后端·python·llm
唐叔在学习2 天前
就算没有服务器,我照样能够同步数据
后端·python·程序员