繁体   English   中英

Python 错误:PermissionError:[WinError 5] 访问被拒绝

[英]Python Error: PermissionError: [WinError 5] Access is denied

所以我目前正在尝试在 Python 3.5 中使用 Tesseract(pytesseract 包装器)。 现在我在办公室,所以我的猜测是没有设置一些愚蠢的权限,这就是为什么我在尝试运行一些非常简单的代码时遇到这个错误。 现在我在这台机器上有管理员权限并且可以更改文件权限......知道我能做些什么来让它运行吗?

如果有的话,它会帮助我在使用不同的操作系统时大致了解系统权限。

   import pytesseract
from PIL import Image
test = Image.open('test.png')
print (pytesseract.image_to_string(test))


    Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
========= RESTART: C:\Users\dmartin\CheckScanScript\TextFromImage.py =========
Traceback (most recent call last):
  File "C:\Users\dmartin\CheckScanScript\TextFromImage.py", line 4, in <module>
    print (pytesseract.image_to_string(test))
  File "C:\Users\dmartin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
    config=config)
  File "C:\Users\dmartin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "C:\Users\dmartin\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "C:\Users\dmartin\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

我有同样的问题。 我解决了这个问题。 首先,您必须在环境变量中添加路径 C:\\Program Files (x86)\\Tesseract-OCR\\。 其次,我注意到如果我的代码在不同的磁盘中,程序无法从文件夹 tessdata 加载语言。 所以我将我的代码从磁盘 D 移动到磁盘 C,它终于可以工作了。

我遇到了同样的问题,我通过以管理员身份运行 IDLE 然后通过 IDLE 打开 .py 文件来解决它。

以管理员身份运行 Python 或 Python IDE 并设置 tesseract_cmd、pytesseract.pytesseract.tesseract_cmd、TESSDATA_PREFIX 和 tessdata_dir_config,如下所示:

from PIL import Image
import pytesseract
tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
pytesseract.pytesseract.tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
TESSDATA_PREFIX= 'D:\Softwares\Tesseract-OCR'
tessdata_dir_config = '--tessdata-dir "D:\\Softwares\\Tesseract-OCR\\tessdata"'
print(pytesseract.image_to_string( Image.open('D:\\ImageProcessing\\f2.jpg'), lang='eng', config=tessdata_dir_config))

我遇到了同样的问题,为 pytesseract 可执行文件添加完整路径对我有用。 因此,如果您已在“C:\\Program Files (x86)\\Tesseract-OCR\\tesseract”中安装了 pytesseract,请确保在您的代码中添加以下路径:-

C:\\Program Files (x86)\\Tesseract-OCR\\tesseract\\tesseract.exe

您的代码如下所示

tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract\\tesseract.exe'
pytesseract.pytesseract.tesseract_cmd = tesseract_cmd
print(pytesseract.image_to_string(Image.open('test.png')))

希望这对你也有用。

我通过通过代码授予文件权限来解决它:

import stat
import os

os.chmod("file",stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IXUSR|stat.S_IRUSR|stat.S_IWUSR|stat.S_IWGRP|stat.S_IXGRP)
os.remove("file")

对我来说,修复的是插入 tesseract.exe 的直接路径

对我来说是这样的:

import pyautogui
from PIL import Image
from pytesseract import *
pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

请注意,您必须自己找到路径!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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