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

14,057

Solution 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

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 3

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 4

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

Share:
14,057
Devin Martin
Author by

Devin Martin

Updated on June 28, 2022

Comments

  • Devin Martin
    Devin Martin almost 2 years

    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