6

My code:

pytesseract.pytesseract.tesseract_cmd = 'C:/Programs/tesseract'
print(pytesseract.image_to_string(Image.open("test.png")))

I get the error: PermissionError: [WinError 5] Access is denied

I then ran the program as administrator, and received the same error. I also changed the permissions of the tesseract folder.

I installed pytesseract using the Python interpreter in Pycharm, and also downloaded the binary from Windows here, using the second option. I extracted the zip folder in C:\Programs

What is causing the error?

4 Answers 4

20

After spending few hours, I found the issue. I am using Win 10 with Python 3.6

img = Image.open('sample1.jpg')
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
result = pytesseract.image_to_string(img)

tesseract.exe executable has to be appended to pytesseract.pytesseract.tesseract_cmd

fyi, earlier I also gave full rights to Tesseract-OCR folder but it may not be required

6

Are you sure this is the full path of your executable?

C:/Programs/tesseract

Because it looks like the path to the executable's folder. Check with the windows explorer what the full path of the executable is and put it in that line:

pytesseract.pytesseract.tesseract_cmd = 'C:/Programs/tesseract/tesseract.exe'
2
  • 1
    Thank you, I tried that but with no result. I still get an error: pytesseract.pytesseract.TesseractError: (1, 'Error opening data file \\Programs\\tesseract\\tessdata/eng.traineddata')
    – Snow
    Commented Aug 6, 2017 at 20:45
  • That is a different error, now the executable is being found. Have you checked if that file eng.traineddata exists in the tessdata folder? I checked the zip file you said you downloaded and the file is not included there, so you might need to follow a tutorial to know how to set up tesseract for first use (check specifically for how to train it or download an already trained config).
    – DWilches
    Commented Aug 6, 2017 at 22:45
5

Set a TESSDATA_PREFIX in your system variables to your tessdata folder. Mine is C:\Program Files (x86)\Tesseract-OCR\tessdata.

TESSDATA_PREFIX system variable

1
  • 2
    Note, for programs like PyCharm and many others, you need to also close the program and re-open it after setting the system environment variable.
    – Silas
    Commented Feb 25, 2018 at 0:25
1

This problem only happens in the case where you set environment variables to direct folder

'C:\Program Files\Tesseract-OCR'

You can say it's not the full path you have to open Tesseract-OCR and click open tessdata. This means you have to save path

'C:\Program Files\Tesseract-OCR\tessdata'

Not the answer you're looking for? Browse other questions tagged or ask your own question.