【问题标题】:OSError: [WinError 740] The requested operation requires elevationOSError: [WinError 740] 请求的操作需要提升
【发布时间】:2020-09-26 09:58:51
【问题描述】:

我有一个简单的代码,其中包含一个名为“try.png”的图像,我想使用 pytesseract 将其从图像转换为文本,但我遇到了一些代码问题。

import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r'tesseract-ocr-setup-4.00.00dev.exe'
img = cv2.imread('try.png')
img= cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
print(pytesseract.image_to_string(img))

但它给了我一个错误。

Traceback (most recent call last):
  File "C:/Users/user 1/PycharmProjects/JARVIS/try.py", line 6, in <module>
    print(pytesseract.image_to_string(img))
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 356, in image_to_string
    return {
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 359, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 270, in run_and_get_output
    run_tesseract(**kwargs)
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 241, in run_tesseract
    raise e
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 238, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 740] The requested operation requires elevation

Process finished with exit code 1

关于如何克服这个错误的任何想法

【问题讨论】:

  • 您是否尝试过使用管理员权限启动代码?
  • 是的,但仍然出现同样的错误
  • 尝试将 tesseract 可执行文件更改为以管理员身份运行:Right Click tesseract.exe -&gt; Properties -&gt; Compability -&gt; Check Run this program as an administrator -&gt; OK。另外,您是如何尝试以管理员权限运行代码的?
  • @K41F4r 等等它是'tesseract.exe' 我把我的路径写成'tesseract-ocr-setup-4.00.00dev.exe' 我刚从网站上下载了这个并将它作为路径。但我没有 tesseract.exe 我只有 'tesseract-ocr-setup-4.00.00dev.exe'。

标签: python python-3.x error-handling tesseract python-tesseract


【解决方案1】:

我猜你还没有在你的系统上安装 tesseract。运行tesseract-ocr-setup-4.00.00dev.exe 进行安装并记下它的安装位置 ($tesseractLocation) 如果在安装时遇到同样的错误,请尝试以管理员权限运行它。 并替换

pytesseract.pytesseract.tesseract_cmd=r'tesseract-ocr-setup-4.00.00dev.exe'

pytesseract.pytesseract.tesseract_cmd=r'$tesseractLocation'

这将解决问题。在脚本中,您必须提及安装目录,而不是安装文件。

【讨论】:

  • 非常感谢,是的,这解决了我的问题。非常感谢您的支持
【解决方案2】:

tesseract-ocr-setup-4.00.00dev.exe 听起来像是一个设置 exe,而不是 tesseract 本身。检查您是否实际安装了 tesseract,如果没有启动 exe 进行安装。

对于 Windows,请从此处下载最新版本: https://github.com/UB-Mannheim/tesseract/wiki

如果您仍然收到OSError: [WinError 740] The requested operation requires elevation,请尝试将 tesseract 可执行文件更改为以管理员身份运行:Right Click tesseract.exe -&gt; Properties -&gt; Compability -&gt; Check Run this program as an administrator -&gt; OK

【讨论】:

  • 非常感谢,是的,这解决了我的问题。非常感谢您的支持
猜你喜欢
  • 2021-09-05
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 2014-10-25
  • 2013-02-08
  • 2021-11-17
  • 1970-01-01
  • 2011-05-10
相关资源
最近更新 更多