{"id":424,"date":"2018-07-09T13:55:09","date_gmt":"2018-07-09T13:55:09","guid":{"rendered":"https:\/\/www.pyxll.com\/blog\/?p=424"},"modified":"2022-08-16T13:01:25","modified_gmt":"2022-08-16T13:01:25","slug":"debugging-your-python-excel-add-in","status":"publish","type":"post","link":"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/","title":{"rendered":"Debug Your Python Excel Add-In"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f6220f6e63d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f6220f6e63d\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#Unit_Testing_and_Running_Code_Outside_of_Excel\" >Unit Testing and Running Code Outside of Excel<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#PyCharm\" >PyCharm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#Visual_Studio_Code\" >Visual Studio Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#Eclipse\" >Eclipse<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#Python_Tools_for_Visual_Studio_PTVS\" >Python Tools for Visual Studio (PTVS)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#Wing_IDE\" >Wing IDE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/#Other\" >Other<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-introduction\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When faced with errors in your Python code, don&#8217;t forget that PyXLL logs all errors to its log file! This can often be a quick and simple way to debug problems when an IDE with debugging capabilities isn&#8217;t available (or even when it, looking at the log file is often the quickest way to see what&#8217;s gone wrong). You can find the location of the PyXLL log file in your pyxll.cfg file. Set the verbosity to &#8216;debug&#8217; in the LOG section of that file to get more detailed logging output.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-unit-testing-and-running-code-outside-of-excel\"><span class=\"ez-toc-section\" id=\"Unit_Testing_and_Running_Code_Outside_of_Excel\"><\/span>Unit Testing and Running Code Outside of Excel<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Build your Python functions that you intend to expose to Excel so that they can be run as separate functions outside of Excel. This way, you can add tests for your code to ensure that it works as intended before trying it in Excel!<\/p>\n\n\n\n<p>If you do this, you can use whatever development tools you are already using without having to worry about connecting to Excel, and you can test changes before rolling them out to users who use your code in Excel.<\/p>\n\n\n\n<p>PyXLL comes with a Python package containing stub functions for all the pyxll functions and function decorators. Install this into your Python environment and you will be able to import and use code that references pyxll functions so that you can run and test them outside of Excel. This package can be installed using pip.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install pyxll\n# or\npip install .\\pyxll-3.x-cpXX-non-winXX.whl\n<\/pre><\/div>\n\n\n<p>The exact file name will depend on the version of PyXLL you have downloaded.<\/p>\n\n\n\n<p>As well as debugging your code it can also be helpful to use a profiler. See <a href=\"https:\/\/www.pyxll.com\/blog\/how-to-profile-python-code-in-excel\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.pyxll.com\/blog\/how-to-profile-python-code-in-excel\/<\/a> for details of how you can profile your Python code in Excel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-pycharm\"><span class=\"ez-toc-section\" id=\"PyCharm\"><\/span>PyCharm<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>[UPDATED 2022-08-04]<\/p>\n\n\n\n<p>PyCharm is a commercial IDE by JetBrains that can be used to debug your Python code while running in Excel.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.jetbrains.com\/pycharm\/\">https:\/\/www.jetbrains.com\/pycharm\/<\/a><\/p>\n\n\n\n<p>For a more detailed guide to debugging Python functions in Excel with PyCharm please see <a href=\"https:\/\/www.pyxll.com\/blog\/debug-python-code-in-excel-with-pycharm\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.pyxll.com\/blog\/debug-python-code-in-excel-with-pycharm\/<\/a>.<\/p>\n\n\n\n<p>There is a community edition, but at the time of writing only the professional (paid) version supports attaching the debugger to Excel to allow you to debug your Python code running in PyXLL.<\/p>\n\n\n\n<p>PyCharm&#8217;s debugger has an &#8220;Attach To Process&#8221; feature that lets you attach the debugger to a running Python process that wasn&#8217;t started by PyCharm. This is perfect for attaching to the Python interpreter running in Excel through PyXLL!<\/p>\n\n\n\n<p>By default, PyCharm will only show you processes to attach to that are called &#8220;python&#8221;. Before you can attach to Excel to debug your PyXLL functions you need to change this by going to File -&gt; Settings. Under the &#8220;Build, Execution, Deployment&#8221; section find the &#8220;Python Debugger&#8221; settings. You will see the setting &#8220;For Attach To Process show processes with names containing:&#8221;, which will be set to &#8220;python&#8221;. Change this to &#8220;excel&#8221; to show only Excel processes, or leave it blank to show all processes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image.png\"><img decoding=\"async\" width=\"1024\" height=\"537\" data-attachment-id=\"1613\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-17\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image.png\" data-orig-size=\"1114,584\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1024x537.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1024x537.png\" alt=\"\" class=\"wp-image-1613\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1024x537.png 1024w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-300x157.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-768x403.png 768w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image.png 1114w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Python Debugger Settings: Attach to Excel<\/figcaption><\/figure>\n\n\n\n<p>Next, with Excel runinng and the PyXLL add-in loaded, in PyCharm go to &#8220;Run -&gt; Attach to Process&#8230;&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1.png\"><img decoding=\"async\" width=\"1024\" height=\"667\" data-attachment-id=\"1614\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-1-6\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1.png\" data-orig-size=\"1551,1011\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-1024x667.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-1024x667.png\" alt=\"\" class=\"wp-image-1614\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-1024x667.png 1024w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-300x196.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-768x501.png 768w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-1536x1001.png 1536w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-1.png 1551w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>PyCharm: Attach to Process&#8230;<\/figcaption><\/figure>\n\n\n\n<p>You will then be prompted with a list of processes to choose from. If you followed the steps above to filter the processes containing &#8220;excel&#8221; you will only see a single process, which is the Excel process you want to debug.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-2.png\"><img decoding=\"async\" width=\"601\" height=\"172\" data-attachment-id=\"1615\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-2-6\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-2.png\" data-orig-size=\"601,172\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-2.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-2.png\" alt=\"\" class=\"wp-image-1615\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-2.png 601w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-2-300x86.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><figcaption>Choose the Excel process to attach to<\/figcaption><\/figure>\n\n\n\n<p>If there are multiple Excel processes running then check which process you want to attach to using the Windows Task Manager. If you are not sure which process is the one you want then you can add a PyXLL function to tell you the process id and call that from Excel. For example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom pyxll import xl_func\nimport os\n\n@xl_func\ndef getpid():\n    # This will return the Excel process ID so you know which\n    # process to attach the debugger to\n    return os.getpid()\n<\/pre><\/div>\n\n\n<p>Once you&#8217;ve selected the Excel process to attach the debugger to you should see the following in the debug console in PyCharm:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3.png\"><img decoding=\"async\" width=\"1024\" height=\"669\" data-attachment-id=\"1616\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-3-5\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3.png\" data-orig-size=\"1644,1074\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-3\" data-image-description=\"&lt;p&gt;Debug Python code in Excel with PyCharm and PyXLL&lt;\/p&gt;\n\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3-1024x669.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3-1024x669.png\" alt=\"\" class=\"wp-image-1616\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3-1024x669.png 1024w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3-300x196.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3-768x502.png 768w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3-1536x1003.png 1536w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/08\/image-3.png 1644w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>With the debugger connected you can now set breakpoints and when you run your functions in Excel it will stop on those breakpoints and allow you to step through your code in the usual way.<\/p>\n\n\n\n<p>If you have any trouble in attaching the debugger, or if PyCharm shows a timeout error when attempting to connect, check the following:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>You do not have any of the packages &#8220;pydevd_pycharm&#8221;, &#8220;pydevd&#8221; or &#8220;ptvsd&#8221; installed. These will interfer with the operation of PyCharm&#8217;s Attach To Process feature unless they are exactly the right version; it is  better to not have them installed at all and to let PyCharm use it&#8217;s own version of pydevd.<br><br>To uninstall these packages run:<br><code>pip uninstall pydevd_pycharm pydevd ptvsd<\/code><br><br>Check your &#8220;site-packages&#8221; folder to make sure they have been removed.<br>\u00a0<\/li><li>You are using the latest version of PyCharm. This post was written using PyCharm 2022.2 (Professional Edition).<br>\u00a0<\/li><li>Check your PyXLL log file for any errors.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-visual-studio-code\"><span class=\"ez-toc-section\" id=\"Visual_Studio_Code\"><\/span>Visual Studio Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For a more detailed guide to debugging Python functions in Excel with VS Code please see <a href=\"https:\/\/www.pyxll.com\/blog\/use-vs-code-to-debug-python-functions-in-excel\/\">Use VS Code to Debug Python Functions in Excel<\/a>.<\/p>\n\n\n\n<p>Visual Studio Code (or VS Code) is a lightweight programming IDE with extensions for many languages, including Python. The Python extension for VS Code features a debugger than can be used to debug Python code running in Excel.<\/p>\n\n\n\n<p>If you don&#8217;t already have VS Code and the Python extension, you can download them from the links below.<br><a href=\"https:\/\/code.visualstudio.com\/download\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/code.visualstudio.com\/download<\/a><br><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.python\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.python<\/a><\/p>\n\n\n\n<p>If you are new to developing Python code in VS Code, there is a tutorial available here:<br><a href=\"https:\/\/code.visualstudio.com\/docs\/python\/python-tutorial\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/code.visualstudio.com\/docs\/python\/python-tutorial<\/a><\/p>\n\n\n\n<p>See the following link for the VS Code documentation on debugging Python code<br><a href=\"https:\/\/code.visualstudio.com\/docs\/python\/debugging\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/code.visualstudio.com\/docs\/python\/debugging<\/a><\/p>\n\n\n\n<p>Once you have installed and familiarised yourself with VS Code, you are ready to debug your Python code running in Excel.<\/p>\n\n\n\n<p>To start debugging click the &#8220;Run and Debug&#8221; button in VS Code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image.png\"><img decoding=\"async\" width=\"1024\" height=\"651\" data-attachment-id=\"1606\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-16\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image.png\" data-orig-size=\"1201,763\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"&lt;p&gt;Attach VS Code to Python in Excel&lt;\/p&gt;\n\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-1024x651.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-1024x651.png\" alt=\"\" class=\"wp-image-1606\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-1024x651.png 1024w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-300x191.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-768x488.png 768w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image.png 1201w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>If you already have some Run Configurations set up for your project, click the down arrow to the right of the currently selected run configuration and select &#8220;Add Configuration&#8230;&#8221;.<\/p>\n\n\n\n<p>If you do not have any Run Configurations yet you will see a blue button &#8220;Run and Debug&#8221;. Click that to create your first run configuration.<\/p>\n\n\n\n<p>When prompted to select a debugger select &#8220;Python&#8221;, and then for the debug configuration select &#8220;Attach using Process ID&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2.png\"><img decoding=\"async\" width=\"1024\" height=\"651\" data-attachment-id=\"1609\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-2-5\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2.png\" data-orig-size=\"1201,763\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2-1024x651.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2-1024x651.png\" alt=\"\" class=\"wp-image-1609\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2-1024x651.png 1024w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2-300x191.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2-768x488.png 768w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-2.png 1201w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>After selecting &#8220;Attach using Process ID&#8221; you will be shown a list of running processes. Type&#8221;EXCEL.EXE&#8221; into the drop down and select the Excel process. This will attach the debugger to the Python interpreter running in Excel. You should already have Excel running with the PyXLL add-in loaded at this stage.<\/p>\n\n\n\n<p>After a short delay the status bar at the bottom of VS Code will change color to indicate that the debugger is attached. You will also see the debug icons at the top of the VS Code window.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3.png\"><img decoding=\"async\" width=\"1024\" height=\"651\" data-attachment-id=\"1610\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-3-4\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3.png\" data-orig-size=\"1201,763\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3-1024x651.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3-1024x651.png\" alt=\"\" class=\"wp-image-1610\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3-1024x651.png 1024w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3-300x191.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3-768x488.png 768w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2022\/07\/image-3.png 1201w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>If you get an error at this stage, check the PyXLL log file. One common error is that a conflicting version of the Python package &#8220;pydevd&#8221; has already been imported. If that is the case, remove that package from your Python environment so the VS Code package can be used instead and try again.<\/p>\n\n\n\n<p>Once the debugger is connected you can set break points and debug your code as it runs in Excel. When you have finished debugging use the disconnect button in the VS Code debug toolbar to disconnect from Excel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-eclipse\"><span class=\"ez-toc-section\" id=\"Eclipse\"><\/span>Eclipse<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To debug Python code with Eclipse you must first install the &#8220;PyDev&#8221; plugin. If you don&#8217;t have this installed already, go to &#8220;Help -&gt; Install new software&#8221; in Eclipse.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"327\" height=\"344\" data-attachment-id=\"454\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/pydev-install\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install.png\" data-orig-size=\"327,344\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pydev-install\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install.png\" alt=\"\" class=\"wp-image-454\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install.png 327w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install-285x300.png 285w\" sizes=\"(max-width: 327px) 100vw, 327px\" \/><\/figure>\n\n\n\n<p>Add the PyDev repository &#8220;http:\/\/www.pydev.org\/updates&#8221; and select the PyDev package.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"597\" height=\"641\" data-attachment-id=\"455\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/pydev-install-2\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install-2.png\" data-orig-size=\"597,641\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pydev-install-2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install-2.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install-2.png\" alt=\"\" class=\"wp-image-455\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install-2.png 597w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-install-2-279x300.png 279w\" sizes=\"(max-width: 597px) 100vw, 597px\" \/><\/figure>\n\n\n\n<p>Click &#8220;Next&#8221; to continue the installation and follow the instructions. Once finished Eclipse will restart.<\/p>\n\n\n\n<p>Set up a Python interpreter in Eclipse that matches the one you are using with PyXLL. To do this, go to &#8220;Window -&gt; Preferences&#8221; and find the &#8220;Python Interpreter&#8221; settings under &#8220;PyDev -&gt; Interpreters&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"995\" height=\"641\" data-attachment-id=\"456\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/pydev-interpreter\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-interpreter.png\" data-orig-size=\"995,641\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pydev-interpreter\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-interpreter.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-interpreter.png\" alt=\"\" class=\"wp-image-456\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-interpreter.png 995w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-interpreter-300x193.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-interpreter-768x495.png 768w\" sizes=\"(max-width: 995px) 100vw, 995px\" \/><\/figure>\n\n\n\n<p>Once that&#8217;s complete, start Excel as usual and then attach to it by going to &#8220;Pydev -&gt; Attach to Process&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"549\" height=\"174\" data-attachment-id=\"457\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/pydev-attach\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-attach.png\" data-orig-size=\"549,174\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pydev-attach\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-attach.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-attach.png\" alt=\"\" class=\"wp-image-457\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-attach.png 549w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-attach-300x95.png 300w\" sizes=\"(max-width: 549px) 100vw, 549px\" \/><\/figure>\n\n\n\n<p>Note that by default, the processes are filtered by &#8220;<em>python<\/em>&#8220;. You will have to change this filter to find the Excel process to attach to.<\/p>\n\n\n\n<p>Next, select the Python interpreter set up previously that matches the one used by PyXLL.<\/p>\n\n\n\n<p>Once attached, you can now set breakpoints and the debugger will stop when they are hit. When a breakpoint is hit, you can then inspect variables and step through your code.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"730\" height=\"688\" data-attachment-id=\"458\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/pydev-breakpoint\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-breakpoint.png\" data-orig-size=\"730,688\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pydev-breakpoint\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-breakpoint.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-breakpoint.png\" alt=\"\" class=\"wp-image-458\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-breakpoint.png 730w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/pydev-breakpoint-300x283.png 300w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><\/figure>\n\n\n\n<p>Older versions of the Pydev plugin for Eclipse did not have this &#8220;Attach to Process&#8221; option. If you are using an older version that does not have this option you should consider updating. Alternatively, you can use the &#8220;Start debug server&#8221; option and use &#8220;pydevd.set_trace&#8221; to connect to the debug server. See <a href=\"http:\/\/www.pydev.org\/manual_adv_remote_debugger.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.pydev.org\/manual_adv_remote_debugger.html<\/a> for more details.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-tools-for-visual-studio-ptvs\"><span class=\"ez-toc-section\" id=\"Python_Tools_for_Visual_Studio_PTVS\"><\/span>Python Tools for Visual Studio (PTVS)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python Tools for Visual Studio (PTVS) is a plugin for Visual Studio for the development of Python code. It has an interactive debugger that can be used to debug Python code running in Excel via PyXLL.<\/p>\n\n\n\n<p><a href=\"https:\/\/visualstudio.microsoft.com\/vs\/features\/python\/\">https:\/\/visualstudio.microsoft.com\/vs\/features\/python\/<\/a><\/p>\n\n\n\n<p>You&#8217;ll need to have Visual Studio installed. For instructions for how to install the PTVS plugin see <a href=\"https:\/\/docs.microsoft.com\/en-gb\/visualstudio\/python\/installing-python-support-in-visual-studio\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/en-gb\/visualstudio\/python\/installing-python-support-in-visual-studio<\/a>. You run the Visual Studio installer, select &#8216;Modify&#8217; and add Python language support to your Visual Studio install.<\/p>\n\n\n\n<p>Start Excel as usual, then in Visual Studio, go to &#8220;Debug -&gt; Attach to Process&#8230;&#8221; and find EXCEL.EXE. When you select it, it should show &#8220;Python Code&#8221; in the &#8220;Attach To&#8221; box to indicate it has detected the process has Python code it can debug. If it shows more than just &#8220;Python code&#8221; in the &#8220;Attach To&#8221; box, click &#8220;Select&#8230;&#8221; next to it, check &#8220;Debug these code types&#8221; and select &#8220;Python&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"856\" height=\"608\" data-attachment-id=\"446\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/ptvs-attach-3\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-attach-2.png\" data-orig-size=\"856,608\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"ptvs-attach\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-attach-2.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-attach-2.png\" alt=\"\" class=\"wp-image-446\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-attach-2.png 856w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-attach-2-300x213.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-attach-2-768x545.png 768w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/figure>\n\n\n\n<p>Click &#8220;Attach&#8221;, and now you can set breakpoints in Visual Studio and it will pause the execution of your code when those breakpoints are hit. You can then step though your code and inspect variables.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1017\" height=\"690\" data-attachment-id=\"448\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/ptvs-breakpoint\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-breakpoint.png\" data-orig-size=\"1017,690\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"ptvs-breakpoint\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-breakpoint.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-breakpoint.png\" alt=\"\" class=\"wp-image-448\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-breakpoint.png 1017w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-breakpoint-300x204.png 300w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-breakpoint-768x521.png 768w\" sizes=\"(max-width: 1017px) 100vw, 1017px\" \/><\/figure>\n\n\n\n<p>Depending on your debugging options, pressing &#8220;Stop&#8221; in Visual Studio may terminate the Excel process. There&#8217;s no need to stop the debugger, but if you want to you can select &#8220;Detach All&#8221; from the Debug menu to detach without terminating Excel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-wing-ide\"><span class=\"ez-toc-section\" id=\"Wing_IDE\"><\/span>Wing IDE<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Wing IDE is a dedicated Python development environment with an integrated visual debugger. The Wing debugger can be used to step through and debug Python code running in Excel.<\/p>\n\n\n\n<p><a href=\"https:\/\/wingware.com\/\">https:\/\/wingware.com\/<\/a><\/p>\n\n\n\n<p>Either &#8220;Wing Pro&#8221; and &#8220;Wing Personal&#8221; can be used and the instructions are the same for each.<\/p>\n\n\n\n<p>Start by finding the folder where Wing IDE is installed. If you are not sure or can&#8217;t find it go to <em>Help -&gt; About..<\/em>.<em> <\/em>in Wing and you will find the folder where it says &#8220;Install Directory&#8221;. Go to that folder on your computer and copy the file <em>wingdbstub.py <\/em>to the folder containing your Python code that you want to debug.<\/p>\n\n\n\n<p>Open the <em>wingdbstub.py<\/em> file that you have just copied and make the following changes:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Check <code>WINGHOME <\/code>is set to the folder where Wing IDE is installed to<\/li><li>Set <code>kEmbedded = 1<\/code><\/li><\/ul>\n\n\n\n<p>For the debugger to work, the <em>wingdbstub<\/em> module must be imported. This can either be done by adding &#8220;import wingdbstub&#8221; to one of the Python modules are you using, or you can add <em>wingdbstub<\/em> to the <em>modules<\/em> list in your pyxll.cfg file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport wingdbstub\n<\/pre><\/div>\n\n\n<p>In Wing IDE click the Debug icon at the bottom left of the application window and select &#8220;Accept Debug Connections&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"365\" height=\"233\" data-attachment-id=\"1350\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/debugging-your-python-excel-add-in\/image-12\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2020\/03\/image.png\" data-orig-size=\"365,233\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2020\/03\/image.png\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2020\/03\/image.png\" alt=\"\" class=\"wp-image-1350\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2020\/03\/image.png 365w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2020\/03\/image-300x192.png 300w\" sizes=\"(max-width: 365px) 100vw, 365px\" \/><\/figure>\n\n\n\n<p>Now restart Excel or reload the PyXLL add-in so that the <em>wingdbstub <\/em>module is imported and it will connect to the Wing IDE debugger. Set some breakpoints in your code and when the Python code running in Excel hits a breakpoint it will pause in the Wing IDE debugger, allowing you to inspect variables and step through the code.<\/p>\n\n\n\n<p>If this doesn&#8217;t work at first try using <em>wingdbstub.Ensure()<\/em> to force wingdbstub to make the connection to the debugger. If it can&#8217;t connect then check that the Wing IDE application is allowed to make network connections in your Windows Firewall settings.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom pyxll import xl_func\nimport wingdbstub\n\n@xl_func\ndef debug_test():\n    wingdbstub.Ensure()\n    return \"Connected Ok!\"\n<\/pre><\/div>\n\n\n<p>To allow the Wing IDE app through the Windows firewall, go to the Start menu on your PC and type &#8220;Allow an app through Windows firewall&#8221;, select &#8220;Change Settings&#8221; and then &#8220;Allow another app&#8230;&#8221;. Navigate to the Wing IDE folder and select the Wing IDE executable from the <em>bin<\/em> folder. Restart Wing IDE and Excel and now the two should be able to connect.<\/p>\n\n\n\n<p>TIP: Why not add this as a ribbon function so it&#8217;s easier to find? See <a href=\"https:\/\/www.pyxll.com\/docs\/userguide\/ribbon.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.pyxll.com\/docs\/userguide\/ribbon.html<\/a> for details of how to do that.<\/p>\n\n\n\n<p>See  <a href=\"https:\/\/wingware.com\/doc\/debug\/debugging-embedded-code\">https:\/\/wingware.com\/doc\/debug\/debugging-embedded-code<\/a>  for more information about how to debug your Python code in Excel with Wing IDE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-other\"><span class=\"ez-toc-section\" id=\"Other\"><\/span>Other<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you are using another IDE it may also have remote debugging capabilities. Search online for help connecting your IDE&#8217;s debugger to an external process (this is commonly referred to as &#8220;remote debugging&#8221;).<\/p>\n\n\n\n<p>If your IDE cannot attach to remote Python processes and you don&#8217;t want to use any of the suggestions above for debugging your code, another alternative is Winpdb. This is a visual debugger, not an IDE, and so you can use it only for debugging and continue to use your chosen IDE for development.<\/p>\n\n\n\n<p>Using a Jupyter Notebook is perect for trying out snippets of code interactively. Read about how you can use Jupyter Notebooks in Excel here <a href=\"https:\/\/www.pyxll.com\/blog\/python-jupyter-notebooks-in-excel\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.pyxll.com\/blog\/python-jupyter-notebooks-in-excel\/<\/a>.<\/p>\n\n\n\n<p><em>Update:<\/em> WinPdb is no longer being maintained and the website is now down. There is however a new fork that is being actively developed &#8211; see <a href=\"https:\/\/pypi.org\/project\/winpdb-reborn\/1.5.0\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/pypi.org\/project\/winpdb-reborn\/1.5.0\/<\/a>. The documentation page no longer exists, but you can find the last version of it here <a href=\"https:\/\/web.archive.org\/web\/20180117043207\/http:\/\/winpdb.org\/docs\/embedded-debugging\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/web.archive.org\/web\/20180117043207\/http:\/\/winpdb.org\/docs\/embedded-debugging\/<\/a> until the documentation for the new fork is available. The call to &#8220;rpdb2.start_embedded_debugger&#8221; can be wrapped in an Excel menu using @xl_menu to start the debugger when needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to step through Python code running in Excel using the most popular Python IDEs.<\/p>\n","protected":false},"author":1,"featured_media":448,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12,2],"tags":[],"class_list":["post-424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-pyxll"],"acf":[],"jetpack_featured_media_url":"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2018\/07\/ptvs-breakpoint.png","jetpack_shortlink":"https:\/\/wp.me\/p7l3LP-6Q","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts\/424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/comments?post=424"}],"version-history":[{"count":1,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts\/424\/revisions"}],"predecessor-version":[{"id":1650,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts\/424\/revisions\/1650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/media\/448"}],"wp:attachment":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/media?parent=424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/categories?post=424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/tags?post=424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}