I am currently using pytesseract which defines an exception class as follows:
class TesseractError(Exception):
def __init__(self, status, message):
self.status = status
self.message = message
self.args = (status, message)
in my main.py, I tried several ways to use this exception for exception handling but I've gotten no "TesseractError" attribute error and no "TesseractError" defined error.
1.
>>> from pytesseract import TesseractError
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TesseractError'
2.
>>> import pytesseract
>>> try: raise pytesseract.TesseractError(True,"True")
... except TesseractError: print("error")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'pytesseract' has no attribute 'TesseractError'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'TesseractError' is not defined
3.
>>> import pytesseract
>>> try: raise TesseractError(True,"True")
... except TesseractError: print("error")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'TesseractError' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'TesseractError' is not defined
However, when I try the following in terminal, it just works.
>>> class ERR(Exception): pass
>>> try: raise ERR()
... except ERR: print("error found")
error found
so it seems it's the importing step is wrong but I don't know what caused it.
image_to_stringis. If you want it, you'll have tofrom pytesseract.pytesseract import TesseractError.__init__.py, everything else must be accessed explicitly by module.