Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Python 2.7 code with VS Code?

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()
like image 725
user365045 Avatar asked May 06 '26 10:05

user365045


1 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 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.

like image 135
Fabio says Reinstate Monica Avatar answered May 08 '26 22:05

Fabio says Reinstate Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!