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

问题描述 投票:3回答:4

所以我目前正在尝试在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
python windows tesseract
4个回答
1
投票

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


1
投票

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


0
投票

我通过代码给文件的Permission解决了它:

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")

0
投票

以管理员身份运行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))
© www.soinside.com 2019 - 2024. All rights reserved.