0

I did pip install pytesseract and installed OCR too. Full error:

Traceback (most recent call last):
  File "c:/Users/Hackry/Documents/pytest/tess.py", line 2, in <module>
    import pytesseract
  File "c:\Users\Hackry\Documents\pytest\pytesseract.py", line 6, in <module>
    text = pytesseract.image_to_string(img)
AttributeError: partially initialized module 'pytesseract' has no attribute 'image_to_string' (most likely due to a circular import)

My code

from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Users/Hackry/AppData/Local/Tesseract-OCR/tesseract.exe' #define tesseract path

img = Image.open('C:/Users/Hackry/Documents/pytest/text.jpg')
text = pytesseract.image_to_string(img)

print(text) 
xrtxn
  • 35
  • 8
  • 1
    Name of your .py file? Is it pytesseract.py? Kindly always paste the whole error, including the initial traceback statement, it helps in solving the issue. – Astrian_72954 Aug 06 '20 at 14:53
  • No I know it can't be pytesseract.py its tess.py – xrtxn Aug 06 '20 at 14:55
  • I see, then am not sure what's going on, give me some time, I'll try to sort it. – Astrian_72954 Aug 06 '20 at 14:58
  • 2
    You have a script named `c:\Users\Hackry\Documents\pytest\pytesseract.py`, that's being imported instead of the actual module. Rename that, and remove any `pytesseract.pyc` or similar file in the same directory. – jasonharper Aug 06 '20 at 15:40

0 Answers0