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

So I am currently trying to use Tesseract (pytesseract wrapper) in Python 3.5. 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


Solution 1:[1]

I've had same problem. I solved this. First you must add path C:\Program Files (x86)\Tesseract-OCR\ in environment variables. Second I noticed if my code in differen disk, programm can't load language from folder tessdata. So I move my code from Disk D to Disk C, and it's finally work.

Solution 2:[2]

I faced this same issue and adding complete path for the pytesseract executable has worked for me. 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\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.

Solution 3:[3]

I had the same issue and I resolved it by running IDLE as an Administrator and then opening the .py file thru IDLE.

Solution 4:[4]

Run Python or Python IDE as Admin and Set tesseract_cmd, pytesseract.pytesseract.tesseract_cmd, TESSDATA_PREFIX and tessdata_dir_config as follows:

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

Solution 5:[5]

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

Solution 6:[6]

For me what fixed it was inserting the direct path to 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!

Solution 7:[7]

I had the same error. For me, it turned out the file mentioned in the (access denied) error was still held by the system in the background from previous run. I ended the process in the Task Manager of Windows and problem solved.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ???????? ???????
Solution 2 rajeev
Solution 3 Kethran
Solution 4 Sourabh Potnis
Solution 5
Solution 6 Sven Eberth
Solution 7 Mor Sagmon