. Advertisement .
..3..
. Advertisement .
..4..
During the process of opening a file or a folder, but you cannot open it and on the screen you receive the error message “PermissionError: [Errno 13] Permission denied”. This article will show you some ways to fix this error in many different situations.
What is “PermissionError: [Errno 13] Permission denied”?
This is a fairly common error in python related to permissions, file system, etc.. This problem occurs when you cannot open a file or directory, a service on the computer cannot start, etc. Errors may be due to corrupted files, or encrypted files, corrupted user profiles, etc. Even if you log in with the correct username and password, you cannot open it. get that folder. The error messages vary depending on the problem. Below is the display of the error:
PermissionError: [Errno 13] Permission denied:
We have compiled 4 solutions for you. Don’t worry, this problem is easy to deal with. Based on your situation, choose the most appropriate option below.
How to fix the error “PermissionError: [Errno 13] Permission denied”?
Solution 1:
Firstly, you have to check the path. If it is File Path, it is correct. If your program is showing the following is false:
import os
path = r"C:\Users\ssc\Desktop\my_personal_file"
assert os.path.isfile(path)
with open(path, "r") as f: // Error
pass
Please correct as follows:
import os
path = r"C:\Users\ssc\Desktop\my_personal_file\bio.txt"
assert os.path.isfile(path)
with open(path, "r") as f: // Error
pass
Solution 2:
Double check your file status is open or closed. In order for the error not to occur, please make sure it is closed in all of app and somewhere.
Solution 3:
This way you will grant it permission. First create a shortcut with the python.exe extension. Then right-click to select Properties. Adjust the path to “C:\path_to\python.exe” or “C:\path_to\your_script.py”. Finally click “advanced” and select “run as administrator”.
Solution 4:
Assume that you run a Python program:
# Program is used for reading the whole file (absolute path) by using read() function
file = open("python.txt", "r")
content = file.read()
print(content)
file.close()
Then you receive this output:
Traceback (most recent call last):
File "C:/Projects/Tryouts/python.txt", line 2, in <module>
file = open("python.txt", "r")
PermissionError: [Errno 13] Permission denied: 'python.txt'
You can solve this error by opening the command prompt in the mode of administrator and operating the Python script. This solution also can apply in the case you encounter “permissionerror winerror 5 access is denied” error.
If you get this error on Linux, you can operate the script actually like an original user by using the sudo
command.
In addition, you can use the below command to check the permissions of your file:
ls -la
# output
-rw-rw-rw- 1 root srinivas 46 Jan 29 03:42 python.txt
Python can’t read the file in the example above because it is possessed by the root user and you are not running Python as the root user.
By adjusting the permission to either a specific user or everyone, you can handle the problem. Let’s run the following command to make the file executable and accessibale to everyone.
chmod 755 python.txt
Or you simply only offer permission to a particular user by doing:
chown srinivas:admin python.txt
You will get this result after running your program again:
Dear User,
Welcome to Python Tutorial
Have a great learning !!!
Cheers
Conclusion
Above are some ways to handle when encountering “PermissionError: [Errno 13] Permission denied“. This is a common mistake that users make. Find out how to handle it and choose the right solution for the situation you are in. Hope you get the problem resolved soon. If you have any questions, don’t hesitate to contact us immediately. Thank you for reading!
This is an interesting article for you to get more information. It’s worth reading!
Similar errors:
Leave a comment