The “PermissionError: [winerror 5] access is denied or the Winerror 5 access is denied” issue 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.
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?
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
- Click on the search button in the taskbar and type “cmd”. Right-click on the Command Prompt and select Run as Administrator.
- Write the following command and press “Enter”.
pip install pydirectory
- 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
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.
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.