Pytesseract is failing with PermissionError: [WinError 5] Access is denied due to undeletable file
Pytesseract is failing with PermissionError: [WinError 5] Access is denied due to undeletable file
我从 https://github.com/UB-Mannheim/tesseract/wiki 安装了 64 位版本
然后 pip install pytesseract
cv2 没有引起任何问题
我的代码:
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread("test.png")
text = pytesseract.image_to_string(img)
print(text)
我的代码在第 6 行失败
PermissionError: [WinError 5] Access is denied: 'C:\Users\nicol\AppData\Local\Temp\tess_puh3wgus'
它似乎在功能上失败了
def cleanup(temp_name):
""" Tries to remove temp files by filename wildcard path. """
for filename in iglob(temp_name + '*' if temp_name else temp_name):
try:
remove(filename)
except OSError as e:
if e.errno != ENOENT:
raise e
删除函数中的第 131 行(文件名)。
它似乎试图删除临时文件但失败了,因为系统拒绝访问所以-
我试过 运行 Spyder IDE 具有管理员权限,我试过给 C:\Program Files\Tesseract-OCR\tesseract.exe 完全权限。我 运行 完整的 anaconda 更新。我还尝试将 TEMP 和 TMP 系统变量的路径更改为不需要管理员权限 (C:\Temp) 的位置。
PermissionError: [WinError 5] Access is denied: 'C:\Temp\tess_hxw9iwvr.PNG'
到目前为止,我已经确定了问题 pytesseract.py 脚本创建了所提供图像的副本,一个具有所需输出的文本文件和一个 0B 空文件,所有这些文件在格式 tess_[a-z0- 中都是同义词9].扩展。问题是由空文件引起的,当我尝试删除它时它需要提升(因为我是我的系统管理员所以我有)我按确定它短暂地进入 0% 删除并且它说访问被拒绝后因为需要管理员权限再试一次或取消。
prompt try again
我猜 cleanup() 函数试图删除 () 文件并被拒绝访问。
禁用 pytesseract.py 的 cleanup() 函数可以掩盖问题,但我设法通过 3 个未删除的 "temporary" 文件的附属文件获得了预期的输出。 运行 只有当我尝试删除文件时,脚本似乎再次用新文件替换了 0B 文件。
我从 https://github.com/UB-Mannheim/tesseract/wiki 安装了 64 位版本
然后 pip install pytesseract
cv2 没有引起任何问题
我的代码:
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread("test.png")
text = pytesseract.image_to_string(img)
print(text)
我的代码在第 6 行失败
PermissionError: [WinError 5] Access is denied: 'C:\Users\nicol\AppData\Local\Temp\tess_puh3wgus'
它似乎在功能上失败了
def cleanup(temp_name):
""" Tries to remove temp files by filename wildcard path. """
for filename in iglob(temp_name + '*' if temp_name else temp_name):
try:
remove(filename)
except OSError as e:
if e.errno != ENOENT:
raise e
删除函数中的第 131 行(文件名)。
它似乎试图删除临时文件但失败了,因为系统拒绝访问所以-
我试过 运行 Spyder IDE 具有管理员权限,我试过给 C:\Program Files\Tesseract-OCR\tesseract.exe 完全权限。我 运行 完整的 anaconda 更新。我还尝试将 TEMP 和 TMP 系统变量的路径更改为不需要管理员权限 (C:\Temp) 的位置。
PermissionError: [WinError 5] Access is denied: 'C:\Temp\tess_hxw9iwvr.PNG'
到目前为止,我已经确定了问题 pytesseract.py 脚本创建了所提供图像的副本,一个具有所需输出的文本文件和一个 0B 空文件,所有这些文件在格式 tess_[a-z0- 中都是同义词9].扩展。问题是由空文件引起的,当我尝试删除它时它需要提升(因为我是我的系统管理员所以我有)我按确定它短暂地进入 0% 删除并且它说访问被拒绝后因为需要管理员权限再试一次或取消。
prompt try again
我猜 cleanup() 函数试图删除 () 文件并被拒绝访问。 禁用 pytesseract.py 的 cleanup() 函数可以掩盖问题,但我设法通过 3 个未删除的 "temporary" 文件的附属文件获得了预期的输出。 运行 只有当我尝试删除文件时,脚本似乎再次用新文件替换了 0B 文件。