Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinError 5:Access denied PyTesseract

I know this question has already been answered on this site, however, none of the solutions I looke up the internet seemed to work. Here's what I tried:

  • Giving all permissions to my python file
  • Changing PATH variable to point to my tesseract folder
  • Running IDLE as administrator and then executing the file from there

This error is quite bothering me now and I can't advance any further because of it.

Here's my code if that's going to help:

import pytesseract
import sys
import argparse
try:
    import Image
except ImportError:
    from PIL import Image
from subprocess import check_output
pytesseract.pytesseract.tesseract_cmd = 'C:\Program Files\Tesseract-OCR'
c=pytesseract.image_to_string(Image.open('img.png'))
print(c)

Traceback:

Traceback (most recent call last):
  File "C:\Users\Hp\Desktop\bot.py", line 12, in <module>
    c=pytesseract.image_to_string(Image.open('captcha.png'))
  File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
  File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
  File "C:\Python\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
  File "C:\Python\lib\subprocess.py", line 992, in _execute_child
startupinfo)
PermissionError: [WinError 5] Accès refusé
like image 349
Oussama Boussif Avatar asked Sep 01 '17 16:09

Oussama Boussif


People also ask

What is Pytesseract library in Python?

Pytesseract or Python-tesseract is an OCR tool for python that also serves as a wrapper for the Tesseract-OCR Engine. It can read and recognize text in images and is commonly used in python ocr image to text use cases.

Does Pytesseract need tesseract?

You can install Python packages, but also non-Python packages with the Anaconda Prompt. Since tesseract is non-Python package needed to use pytesseract, I think the Anaconda distribution of Python and the conda package manager is the way to go.

What is the difference between tesseract and Pytesseract?

Both are OCR wrappers for Python; however, pytesseract is based on Googles OCR API and tesseract isn't. I would suggest using pytesseract based on the fact that it will be maintained better, but with that being said, try them both out and use whichever works better for you.


2 Answers

I suspect a few things, not sure about any though.

First and the most obvious, the path to Tesseract is not complete. It should be something like:

tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

I believe your path points to a directory/folder and not an executable, though only you can confirm that. Let me know if this is incorrect, I see something else too that doesn't seem right at first, but needs more investigation.

like image 125
0xc0de Avatar answered Oct 22 '22 14:10

0xc0de


I encountered same problem, and I fixed it as 0xc0de said, change the below line:

pytesseract.pytesseract.tesseract_cmd=r"C:\MyApps\Tesseract-ocr\"

to:

pytesseract.pytesseract.tesseract_cmd="C:\\MyApps\\Tesseract-ocr\\tesseract.exe"
like image 17
Fatalerr Avatar answered Oct 22 '22 12:10

Fatalerr