Fixes

Permissionerror: [winerror 5] access is denied [Fixed Completely]

The “PermissionError: [winerror 5] access is denied” is a very common error message that appears while using python on Windows. Almost all of the python developers encounter this error message on some stage of their coding.  This error might appear while they are importing python on some programming tool or it might appear while running a script. In this article, we have compiled some solutions to rectify the “[WinError 5] Access is denied” error completely from Python.

[winerror 5] access is denied Error on Python
Error Message

What Causes the Access is Denied Error?

The main reason behind the error of access denial is that you are only allowed to run programs and not directories. This error will occur if we try to run a directory.

This error can occur due to incorrect syntax of the code or any older version of the Python.

What to do if you get the “winerror 5 access is denied” Message in CMD or Python?

Fix Issue Automatically
If you want to have this issue fixed automatically on your computer and diagnose, list, and rectify any registry errors, we recommend that you try using the Restoro Repair Tool that can easily do all of this at a single click. It has been rated Great by Trustpilot so you don’t have to worry about anything.

1. Solution 1: Run as Administrator

If you are trying to install python directories from your command prompt and the “winerror 5 access is denied” error appears then there is nothing to worry about. This error can be solved very easily and quickly. Just follow the steps below to resolve this issue

  1. Click on the search button in the taskbar and type “cmd”. Right-click on the Command Prompt and select Run as Administrator.
    Running Command Prompt as Administrator
    Command Prompt
  2. Write the following command and press “Enter”.
    pip install pydirectory
    Running the "pip install pydirectory" command in the command Prompt
    Command
  3. Check if this error appears again.

2.Solution 2: Set Permission

Sometimes syntax used for different versions of python can be the reason behind this error. For example, if you wanted to set permission for python 2, the command used was as follows

os.chmod('spam.txt', 777)

This will be considered wrong if you are using python 3 because this syntax is outdated and will lead to a syntax error. The syntax used to access permission in python 3 is a little bit different. The command for python 3 is as follows.

os.chmod('spam.txt', 0o777)

3. Solution 3: Give Path To The Image

If you are opening an image in your code, this error might occur because of the wrong syntax. You will get this permission denial if you write the code in the following syntax

img = cv2.imread('G:/project/OCR/FDA.png')

This issue an be resolved by adding an “r” before the path of the image. For example, the correct syntax of the code which will not cause any error will be as follows.

img = cv2.imread(r'G:/project/OCR/FDA.png')

4. Solution 4: Update Python

Sometimes this error arises due to an old version of Python. The latest version of python has all the updates and fixes of the bugs that were present in the older versions. If you are using version 3.7.2 of python then make sure you update it to version 3.7.3 because the older version contains some bugs which might be the reason behind this error.

If you need further assistance, contact here. You can also seek help from the official Python page.

Back to top button