简体   繁体   中英

pytesseract gives an error PermissionError: [WinError 5] Access is denied

I'm using pytesseract in Python for pdf. But I'm getting permission error in windows 10. I have install tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe from https://github.com/UB-Mannheim/tesseract/wiki I have also poppler-20.09.0 files. and I`m using python 3.8.0

import pdf2image
import PyPDF2
import os
try:
   from PIL import Image
except ImportError:
   import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR'

def pdf_to_img(pdf_file):
    print('pdf_file = ', pdf_file)
    return pdf2image.convert_from_path(pdf_file, dpi=200, fmt='jpg',
                                   poppler_path=r'F:\lokesh\resume_script\poppler-20.09.0\bin')


def ocr_core(file):
    text = pytesseract.image_to_string(file,)
    return text


def print_pages(pdf_file):
    images = pdf_to_img(pdf_file)
    for pg, img in enumerate(images):
        print(ocr_core(img))


print_pages("aa.pdf")

when I run this code. it gives this error.

Traceback (most recent call last):
File "test.py", line 84, in <module>
  print_pages("aa.pdf")
File "test.py", line 81, in print_pages
  print(ocr_core(img))
File "test.py", line 74, in ocr_core
  text = pytesseract.image_to_string(file,)
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 344, in image_to_string
  return {
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 347, in <lambda>
  Output.STRING: lambda: run_and_get_output(*args),
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 258, in run_and_get_output
  run_tesseract(**kwargs)
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 229, in run_tesseract
  raise e
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 226, in run_tesseract
  proc = subprocess.Popen(cmd_args, **subprocess_args())
File "F:\python\lib\subprocess.py", line 854, in __init__
  self._execute_child(args, executable, preexec_fn, close_fds,
File "F:\python\lib\subprocess.py", line 1307, in _execute_child
  hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied

how can we solve this error in windows

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR'

需要是

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM