PermissionError: [Errno 13] Permission denied in Python
Hello guys, I have create an application with Python 3.9 to read data from .csv file.
I have a csv file with format as below:
1, Marry,24,female
2,Jackson,22,male
3,Herry,32,male
4,Marry,12,female
5,Jackson,45,male
6,IceBulk,56,female
7,Mundy,78,male
8,Zacky,3,female
9,Buddy,14,male
And bellow is my Python code:
import csv
with open("human_phase1.csv", "r") as file:
reader = csv.reader(file)
for r in reader:
print(r)
But when running code I got an exception PermissionError: [Errno 13] Permission denied: 'human_phase1.csv'.
Traceback (most recent call last):
File "test.py", line 3, in <module>
with open("human_phase1.csv", "r") as file:
PermissionError: [Errno 13] Permission denied: 'human_phase1.csv'
I don't know how to change permission to access csv file. I think I'm not in root mode.
Anyone can suggest any solution for me?
I'm using Python 3.9 and run in Window 10.
- A0
Armin Habibi Dec 02 2021
You can run ls -la command to check permission of you csv file. For example:
-rw-rw-rw- 1 root staff 46 Oct 5 07:01 human_phase1.csv
if you see content root in output, it's mean you file in root permission. In this case you can run command below to grant permission for your app:
chown admin:admin human_phase1.csv
It's mean you will create
admin
user and theadmin
group the owners of the file.I hope it solve issue for you.
- G-1
Gabriel Mandap Dec 02 2021
Yeah, Your Python programming is can not permission to access to
human_phase1.csv
file. To grant permission, in your terminal execute typing command:chown admin:admin human_phase1.csv
Or if it's not work, you can try command:
chmod 755 human_phase1.csv
It worked well for me.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.