PermissionError with pytesseract

Viewed 9409

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

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

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'

Related