How to debug Python 2.7 code with VS Code?

2024/10/11 20:23:50

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()
Answer

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.

https://en.xdnf.cn/q/69733.html

Related Q&A

Python Sequence of Numbers

Ive decided not to waste my summer and start learning python. I figured Id start learning looping techniques so I wanted to start with a basic list of numbers, aka, write a for loop that will generate…

Object initializer syntax (c#) in python?

I was wondering if there is a quick way to initialise an object in python. For example in c# you can instantiate an object and set the fields/properties like...SomeClass myObject = new SomeClass() { va…

Plotly.io doesnt see the psutil package even though its installed

Im trying to execute the following code:import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib %matplotlib inline import seaborn as snsimport plotly.graph_objects as g…

How to get MultiCells in Pyfpdf Side by side?

I am making a table of about 10 cells with headings in them. They will not fit accross the page unless I use multi_cell option. However I cant figure out How to get a multi_cell side by side. When I ma…

Django: Require Checkbox to be ticked to Submit Form

Im creating a form in Django (using ModelForm). There are many checkboxes, and I want to make it so that one of these must be selected in order to submit the form. I dont mean any one checkbox, but on…

Filtering in django rest framework

In my project I use django rest framework. To filter the results I use django_filters backend. There is my code:models.pyfrom django.db import modelsclass Region(models.Model):name = models.CharField(m…

Efficiency difference between dict.has_key and key in dict in Python [duplicate]

This question already has answers here:Closed 11 years ago.Possible Duplicate:has_key() or in? In Python, therere two ways of deciding whether a key is in a dict:if dict.has_key(key) and if key in di…

python points to global installation even after virtualenv activation

Its a bit weird, I have activated the virtual environment python still points to the global installation.$ which python /usr/bin/python$ source ~/virtualenv/bin/activate (virtualenv)$ which python /usr…

Should I perform both lemmatization and stemming?

Im writing a text classification system in Python. This is what Im doing to canonicalize each token:lem, stem = WordNetLemmatizer(), PorterStemmer() for doc in corpus:for word in doc:lemma = stem.stem(…

Python monkey patch private function

I have a module with a function (call it a()) that calls another function defined in the same module (call it __b()). __b() is a function which speaks to a website via urllib2 and gets some data back.…