0
votes

I have a project where I am using pytesseract. I installed tesseract but every time I am trying to run my code I am getting this error.

pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\\Users\\ekrem\\AppData\\Local\\Tesseract-OCR\\tesseract.exe/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language 'eng' Tesseract couldn't load any languages! Could not initialize tesseract.')

I set the TESSDATA_PREFIX:

enter image description here

I am using windows 10.

And here is my code:

import pytesseract
import os
import shutil


pytesseract.pytesseract.tesseract_cmd="C:\\Users\\ekrem\\AppData\\Local\\Tesseract-OCR\\tesseract.exe"
directory='C:\\Users\\ekrem\\Desktop\\resimler'
for filename in os.listdir(directory):
    b=os.path.join(directory, filename)
    if 'CRN' in pytesseract.image_to_string(b):
        print(b)
        a=pytesseract.image_to_string(b).index('CRN')
        print(pytesseract.image_to_string(b)[a-6:a-1])
    else:
        destination='C:\\Users\\ekrem\\Desktop\\fails'
        c = os.path.join(destination, filename)
        shutil.copyfile(b,c)
1
Says to set the environment variable to the tessdata folder but it seems you've set it to the full path to the .EXE file instead. - Justin Ezequiel
I am getting still the same error - Ekrem Üçüncü
Please update your question if you've indeed set the environment variable to the tessdata folder. - Justin Ezequiel
I editted the question, I am getting the same error - Ekrem Üçüncü

1 Answers

-1
votes

...\\tesseract.exe/eng.traineddata - this path if wrong - you set up TESSDATA_PREFIX wrongly.