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

时间:2014-07-01 23:36:20

标签: python xdebug sublimetext sublimetext3

尝试从较重的IDE转向升华。我注意到它缺少的是与intellij IDE相比的调试。通过研究我了解了XDebug,我相信它可以提供类似的调试。但是,我在设置时遇到了麻烦。

以下是我所做的:

  1. 已安装sublime 3
  2. 已安装的软件包管理器
  3. 使用的包管理器安装XDebug
  4. 注意到文件丢失,因此我通过包管理器删除了包
  5. 克隆了来自martomo(https://github.com/martomo/SublimeTextXdebug
  6. 的回购
  7. 将其放入我的打包文件夹中 enter image description here

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

    {
        // 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
    }
    
  9. 我单独留下了XDebug.sublime-settings文件,只是运行了调试器。

  10. 去了http://localhost:9000(没有发生任何事情,只是有点卡住了)
  11. 我要调试的脚本位于/ Users / wf / Desktop(文件为xdebugTest.py)

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

    我将非常感谢您设置调试参数的任何帮助 谢谢你。

1 个答案:

答案 0 :(得分:2)

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