6

For work I have to use Python 2.7.

But when I use the "debug my python file" function in VS Code, I get an error.

Even with a simple program, like :

print()
user365045
  • 63
  • 1
  • 5
  • 1
    you have to install a previous version of the ms-python extension, they dropped python2 support a few months back – rioV8 May 12 '22 at 11:55

1 Answers1

25

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.

  • In step 2, if you already have another version of the plugin installed, it should be "Click on the 'V' next to 'Uninstall' (More Actions...) and select 'Install another version'" – cmbryan May 18 '23 at 07:58