3

I am facing an issue in the following piece of code. Basically what I am trying to do here is I am trying to check for particular phrases that are present in my data which is OCR'd from an image. I cannot share the image because of reasons. I get error "Backend TkAgg is interactive backend. Turning interactive mode on" while I try to debug the code. But I get normal exception error when run.

imgH = imageShape[0]
imgW = imageShape[1]
imgWx = int(float(imgW*.5))
wordRatio = []
SUBJECTEXISTS = False
dictMatch = defaultdict(str)
try:
    for pattern in patterns:
        for word in pattern:
            if (len(word.text))>3:
                wordStripped = re.sub(r'[^\w\s]', '', word.text.lower())
                # if int(float(word.x0))<=imgWx:
                for subject in subjectList:
                    if wordStripped in subject.lower():
                        if Levenshtein.ratio(wordStripped,subject.lower())>.5 and wordStripped not in transcript_exclusion:
                            SUBJECTEXISTS = True
                            break

except:
    for word in patterns:
        if SUBJECTEXISTS:
            break
        if (len(word.text)) > 3:
            wordStripped = re.sub(r'[^\w\s]', '', word.text.lower())
            # if int(float(word.x0))<=imgWx:
            for subject in subjectList:
                if wordStripped in subject.lower():
                    if Levenshtein.ratio(wordStripped,
                                         subject.lower()) > .5 and wordStripped not in transcript_exclusion:
                        # print("The word: ",wordStripped)
                        lineValue = imageInfo[int(word.lineId)-1]
                        wordsList = lineValue.text.lower().split()
                        wordIdx = wordsList.index(wordStripped)
                        if 'accounting' in wordStripped:
                            pass
                        try:
                            if wordStripped in lineValue.text.lower() and 'in' in wordsList[wordIdx-1]:
                                pass
                            else:
                                SUBJECTEXISTS = True
                                break
                        except:
                            SUBJECTEXISTS = True
                            break

I think the error lies within the usage of break statements below SUBJECTEXISTS. Should I be concerned with this or is it just like a warning? Also I am using Pycharm IDE Does anyone have any idea what the error is?

ezpz4pc
  • 31
  • 1
  • 1
  • 5

2 Answers2

0

after years I mentioned your problem again, please change the backend which is used for mathplotlib:

import matplotlib
matplotlib.use('TkAgg',force=True)
from matplotlib import pyplot as plt
print("Switched to:",matplotlib.get_backend())

see a full answer here

t2solve
  • 657
  • 4
  • 20
  • But I have not used matplotlib in my code at all. So from where might the problem be arising from? – ezpz4pc Oct 17 '22 at 11:47
  • good question, maybe the backend is used by more packages than mathplotlib, or a package is using mathplotlib internal ? maybe you could do a pip freeze to see all packages which are used in your code – t2solve Oct 18 '22 at 07:34
0

This happened to me in VS code whenever I accidentally set a breakpoint, even if I didn't import matplotlib. Unsetting the breakpoint fixed the issue.

Jonathan
  • 101
  • 2