python - 如何使用 xdebug 和 sublime 来调试 python 脚本

标签 python xdebug sublimetext sublimetext3

尝试从较重的 IDE 迁移到 Sublime。我注意到它与 intellij IDE 相比缺少的是调试功能。通过研究,我了解了 XDebug,并且我相信它可以提供类似的调试功能。但是,我在设置时遇到了问题。

这是我所做的:

  1. 已安装 sublime 3
  2. 已安装的包管理器
  3. 使用包管理器安装 XDebug
  4. 注意到文件丢失,因此我通过包管理器删除了该包
  5. 从 martomo 克隆了存储库 ( https://github.com/martomo/SublimeTextXdebug )
  6. 将其放入我的 Packaged 文件夹
    enter image description here

  7. 然后我去了 XDebug.sublime-settings,但我不知道如何配置它(我链接到什么,它需要什么 url,等等...)

    {
        // For remote debugging to resolve the file locations
        // it is required to configure the path mapping
        // with the server path as key and local path as value.
        //
        // Make sure to use absolute path when defining server path,
        // because Xdebug debugger engine does not return symbolic links.
        //
        // Example:
        // "/absolute/path/to/file/on/server" : "/path/to/file/on/computer",
        // "/var/www/htdocs/example/" : "C:/git/websites/example/"
        "path_mapping": {
    
        },
    
        // Determine which URL to launch in the default web browser
        // when starting/stopping a session.
        "url": "",
    
        // An IDE key is used to identify with debugger engine
        // when Sublime Text will start or stop a debugging session.
        //
        // This package does not filter sessions by IDE key,
        // it will accept any IDE key, also ones that do not match this configured IDE key.
        // It is merely used when launching the default web browser with the configured URL.
        "ide_key": "sublime.xdebug",
    
        // Which port number Sublime Text should listen
        // to connect with debugger engine.
        "port": 9000,
    
        // Show super globals in context view.
        "super_globals": true,
    
        // Maximum amount of array children
        // and object's properties to return.
        "max_children": 32,
    
        // Maximum amount of
        // variable data to initially retrieve.
        "max_data": 1024,
    
        // Maximum amount of nested levels to retrieve
        // of array elements and object properties.
        "max_depth": 1,
    
        // Break at first line on session start, when debugger engine has connected.
        "break_on_start": false,
    
        // Break on exceptions, suspend execution
        // when the exception name matches an entry in this list value.
        "break_on_exception": [
            // E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR
            "Fatal error",
            // E_RECOVERABLE_ERROR (since PHP 5.2.0)
            "Catchable fatal error",
            // E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING
            "Warning",
            // E_PARSE
            "Parse error",
            // E_NOTICE, E_USER_NOTICE
            "Notice",
            // E_STRICT
            "Strict standards",
            // E_DEPRECATED, E_USER_DEPRECATED (since PHP 5.3.0)
            "Deprecated",
            // 0
            "Xdebug",
            // default
            "Unknown error"
        ],
    
        // Always close debug windows and restore layout on session stop.
        "close_on_stop": false,
    
        // Do not show possible password values in context output.
        "hide_password": false,
    
        // Show in output parsed response instead of raw XML.
        "pretty_output": false,
    
        // Always launch browser on session start/stop.
        // Note: This will only work if you have the 'url' setting configured.
        "launch_browser": false,
    
        // When launching browser on session stop do not execute script.
        // By using parameter XDEBUG_SESSION_STOP_NO_EXEC instead of XDEBUG_SESSION_STOP.
        "browser_no_execute": false,
    
        // Do not use the debugging window layout.
        "disable_layout": false,
    
        // Window layout that is being used when debugging.
        "debug_layout" : {
            "cols": [0.0, 0.5, 1.0],
            "rows": [0.0, 0.7, 1.0],
            "cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]
        },
    
        // Group and index positions for debug views.
        "breakpoint_group": 2,
        "breakpoint_index": 1,
        "context_group": 1,
        "context_index": 0,
        "stack_group": 2,
        "stack_index": 0,
        "watch_group": 1,
        "watch_index": 1,
    
        // Custom gutter icons for indicating current line or enabled/disabled breakpoints.
        //
        // Do not use same icon for following values, because Sublime Text is unable
        // to use the same icon for different scopes, in case there are duplicate icons
        // detected it will fall back to the corresponding icon in the package.
        "breakpoint_enabled": "circle",
        "breakpoint_disabled": "dot",
        "breakpoint_current": "",
        "current_line": "bookmark",
    
        // Path to Python installation on your system.
        // Which is being used to load missing modules.
        //
        // It is recommended to configure your Python path for Sublime Text 2
        // especially on older UNIX systems, where some modules (xml.parsers.expat)
        // might be missing and could improve performance of package.
        //
        // Example:
        // "python_path" : "/usr/lib/python2.7"
        "python_path" : "",
    
        // Show detailed log information about communication
        // between debugger engine and Sublime Text.
        // Log can be found at Packages/User/Xdebug.log
        "debug": false
    }
    
  8. 我保留了 XDebug.sublime-settings 文件,只运行了调试器。

  9. 访问http://localhost:9000(什么也没发生,只是加载有点卡住了)

我要调试的脚本位于/Users/wf/Desktop(文件为xdebugTest.py)

我应该如何设置url? (我尝试了 http://localhost:9000/Users/wf/Desktop/xdebugTest.py 和 404)

如果您能帮助我设置调试参数,我将不胜感激。
谢谢你。

最佳答案

如果您在 Github 上克隆源代码,您应该已经运行过 README令人惊讶的是,其中包含有关在服务器上安装和设置工作 Xdebug 系统的重要信息。您可能错过的第一个重要信息是 Xdebug是 PHP 服务器的扩展。这是可以理解的,您可能很着急,无论如何都想开始。但是,如果您继续阅读(名称仍然恰当的)自述文件,您会找到 xdebug.org 网站的链接,了解有关在服务器上安装扩展的详细信息,然后是标题为 Configuration 的综合部分。除了已经提供的深思熟虑的注释之外,它还引导读者浏览 .sublime-settings 文件中的每个项目。最后,有一个名为 Troubleshoot 的部分它引导您完成启动 session 、设置断点和监视表达式、异常处理、自定义布局等。所有这些文档甚至应该使 PHP 开发人员能够启动并运行它。希望下次您遇到类似情况时您会检查一下。

关于python - 如何使用 xdebug 和 sublime 来调试 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24520753/

相关文章:

ruby - Sublime Text 3 和 Rspec,构建错误

sublimetext - 如何在 sublime text 的 markdown 中制作 "todo"?

python - matplotlib 曲面图隐藏了应该在前面的散点

python - 僵尸进程,我们又来了

php-debug 控制台未在 Atom 中显示

Sass 支持 Sublime Text 2?

python - ISBN 用作主键,现在我想将非书籍内容添加到数据库中 - 我应该迁移到 EAN 吗?

python - Ctrl-C 结束我的脚本,但它没有被 KeyboardInterrupt 异常捕获

ubuntu - Sublime Text 3(带有 Xdebug 客户端插件)+ Vagrant VM(Ubuntu)

php - 关闭语句后的mysqli + xdebug断点导致许多警告