How to debug Python 2.7 code with VS Code?

Question:

For work I have to use the 2.7 version of Python, it’s my only choice.

So I’m trying to use VS Code as an IDE, I managed to set my interpreter correctly, but when I use the "debug my python file" function in VS Code, I get an error.

Even with a simple program, like :

print()
Asked By: user365045

||

Answers:

As rioV8 said in a comment, 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:

  1. Open the Extensions pane from the bar on the left and find Python
  2. Click on the gear icon and select "Install another version"
  3. Choose v2021.9.1246542782.
  4. After it’s finished, restart VS Code.

If you want to understand why you need version v2021.9.1246542782:

The component that provides support to the language is Jedi, and the release notes of version 0.17.2 (2020-07-17) say that

This will be the last release that supports Python 2 and Python 3.5.
0.18.0 will be Python 3.6+.

And according to the release notes of the Python extension, the latest version that was based on Jedi 0.17 was 2021.9.3 (20 September 2021), because the following one (2021.10.0, 7 October 2021) says

Phase out Jedi 0.17

Is that all? No, because the selection that VS Code offers when selecting previous versions uses a different numbering scheme. Anyway, the latest one of the v2021.9.* branch is v2021.9.1246542782, which I suppose corresponds to 2021.9.3, so it’s the one you need.