pytesseract给出错误PermissionError:[WinError 5]访问被拒绝

时间:2020-09-24 14:40:42

标签: python pdf ocr tesseract

我在python中使用pytesseract for pdf。但是我在Windows 10中遇到权限错误。 我已经从https://github.com/UB-Mannheim/tesseract/wiki安装了tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe 我也有poppler-20.09.0文件。我正在使用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")

当我运行这段代码时。它给出了这个错误。

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

我们如何在Windows中解决此错误

0 个答案:

没有答案