Debug python 2.7

2023-09-28 Visual Studio Code vscode python config debug

Recently I had to debug old program written years ago using python 2.7. The thing worked quite nicely for more than decade, but last month the version-control system used as data source - Dimensions - was updated and various reports it produces changed their format.

I had to setup my Visual Studio Code to debug such thing. One crucial information came from this Stack Overflow entry:

you have to install a previous version of the Python extension, because in the meanwhile support for Python 2 has been dropped.

To install a previous version you have to:

  • Open the Extensions pane from the bar on the left and find Python
  • Click on the gear icon and select “Install another version”
  • Choose 2021.9.1246542782
  • After it’s finished, restart VS Code.

There is more info on reasons for the version, long story short the version mentioned above is last where was still support for python 2.x.

The debugging then works, we just need to setup the tool to run with proper arguments and we can use it for resolving the problem.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Tool",
            "type": "python",
            "request": "launch",
            "program": "tool.py", // ,"program": "${file}",
            "args" : ["-ini=runtime.ini"],
            "console": "integratedTerminal"
        }
    ]
}

More information on other debug parameters can be found in the editor documentation for debugging.