Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 306
Snow Avatar asked Nov 29 '22 13:11

Snow


2 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

like image 98
Hamid Avatar answered Dec 10 '22 16:12

Hamid


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'
like image 44
Daniel Avatar answered Dec 10 '22 15:12

Daniel