9

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()
1
  • 1
    you have to install a previous version of the ms-python extension, they dropped python2 support a few months back Commented May 12, 2022 at 11:55

1 Answer 1

32

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 2021.9.1246542782.
  4. After it's finished, restart VS Code.

If you want to understand why you need version 2021.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.

Sign up to request clarification or add additional context in comments.

5 Comments

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'"
Before install - uninstall pylance, otherwise the install will be blocked.
Newer version v2022.2.1924087327 is OK: !preview
@PatrickZ I'm no longer working with VS Code and Python 2, so I can't investigate this. My guess is that you are using a different language server, one that still supports Python 2. If you didn't change it manually, maybe it means that the Python extension no longer uses Jedi by default. I think your discovery would be worth an answer, and if you can't find out what happened, it deserves asking a new question about it.
This might be relevant: a Microsoft dev talking about debugpy 1.5 "which will work all the way back to Python 2.7"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.