'PermissionError with pytesseract

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?



Solution 1:[1]

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

Solution 2:[2]

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'

Solution 3:[3]

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'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hamid
Solution 2 Daniel
Solution 3 hrokr