. Advertisement .
..3..
. Advertisement .
..4..
Please help me with this error permissionerror: [errno 13] permission denied:
When I run the following program to read the file and print it out:
# Program to read the entire file (absolute path) using read() function
file = open("python.txt", "r")
content = file.read()
print(content)
file.close()
It throws this error:
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'
Looking forward to everyone’s answers on what caused the error and how to fix it.
The cause: Insufficient privileges on the file or for Python because the root user creates the file. You don’t have permission to modify or read the file, so the error permissionerror: [errno 13] permission denied: occurs.
Solution:
In Windows, you can launch the command prompt in administrator mode and run the Python script to correct the error.
In the case of Linux, the problem can be solved by running the script as the root user using the
sudo
command.Alternately, you can use the following command to examine the file permissions.
By adjusting the permission to either a specific user or everyone, we can resolve the problem. Let’s run the following command to make the file accessible to everyone.
You will see the output below when we run our code again after setting the appropriate permissions.
To fix the error “PermissionError: [Errno 13] Permission denied”. We have compiled 3 solutions for you
👇️ Read more: Solving the error “PermissionError: [Errno 13] Permission denied”