简体   繁体   English

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

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

So I am currently trying to use Tesseract (pytesseract wrapper) in Python 3.5.所以我目前正在尝试在 Python 3.5 中使用 Tesseract(pytesseract 包装器)。 Now Im at the office so my guess is that there are some goofy permissions not set and thats why I get this error trying to run some pretty simple code.现在我在办公室,所以我的猜测是没有设置一些愚蠢的权限,这就是为什么我在尝试运行一些非常简单的代码时遇到这个错误。 Now I do have admnin permissions on this machine and can change file permissions... any idea what I can do to get this to run?现在我在这台机器上有管理员权限并且可以更改文件权限......知道我能做些什么来让它运行吗?

If anything it will help me wrap my head around system permissions in general as I work with different OS.如果有的话,它会帮助我在使用不同的操作系统时大致了解系统权限。

   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

I've had same problem.我有同样的问题。 I solved this.我解决了这个问题。 First you must add path C:\\Program Files (x86)\\Tesseract-OCR\\ in environment variables.首先,您必须在环境变量中添加路径 C:\\Program Files (x86)\\Tesseract-OCR\\。 Second I noticed if my code in differen disk, programm can't load language from folder tessdata.其次,我注意到如果我的代码在不同的磁盘中,程序无法从文件夹 tessdata 加载语言。 So I move my code from Disk D to Disk C, and it's finally work.所以我将我的代码从磁盘 D 移动到磁盘 C,它终于可以工作了。

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

Run Python or Python IDE as Admin and Set tesseract_cmd, pytesseract.pytesseract.tesseract_cmd, TESSDATA_PREFIX and tessdata_dir_config as follows:以管理员身份运行 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))

I faced this same issue and adding complete path for the pytesseract executable has worked for me.我遇到了同样的问题,为 pytesseract 可执行文件添加完整路径对我有用。 So , if you have installed pytesseract in your "C:\\Program Files (x86)\\Tesseract-OCR\\tesseract" make sure in your code you are adding below path:-因此,如果您已在“C:\\Program Files (x86)\\Tesseract-OCR\\tesseract”中安装了 pytesseract,请确保在您的代码中添加以下路径:-

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

Your code would look like below您的代码如下所示

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

Hope this works for you too.希望这对你也有用。

I solved it by give Permission to the file by code:我通过通过代码授予文件权限来解决它:

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

For me what fixed it was inserting the direct path to tesseract.exe对我来说,修复的是插入 tesseract.exe 的直接路径

What it looks like for me is:对我来说是这样的:

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

Note that you will have to find the path yourself!请注意,您必须自己找到路径!

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

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