Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PermissionError: [Errno 13] in Python

Just starting to learn some Python and I'm having an issue as stated below:

a_file = open('E:\Python Win7-64-AMD 3.3\Test', encoding='utf-8')  Traceback (most recent call last):   File "<pyshell#9>", line 1, in <module>     a_file = open('E:\Python Win7-64-AMD 3.3\Test', encoding='utf-8') PermissionError: [Errno 13] Permission denied: 'E:\\Python Win7-64-AMD 3.3\\Test\ 

Seems to be a file permission error, if any one can shine some light it would be greatly appreciated.

NOTE: not sure how Python and Windows files work but I'm logged in to Windows as Admin and the folder has admin permissions.

I have tried changing .exe properties to run as Admin.

like image 585
BenniMcBeno Avatar asked Nov 03 '12 08:11

BenniMcBeno


People also ask

How do I fix errno 13 Permission denied Python?

To fix PermissionError: [Errno 13] Permission denied with Python open, we should make sure the path we call open with is a file. to make sure that the path is a path to a file with os. path. isfile before we call open to open the file at the path .

What is error number 13 in Python?

The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary permissions. To fix this error, use the chmod or chown command to change the permissions of the file so that the right user and/or group can access the file.

Why does Python say Permission denied?

Permission denied simply means the system is not having permission to write the file to that folder. Give permissions to the folder using "sudo chmod 777 " from terminal and try to run it.


1 Answers

When doing;

a_file = open('E:\Python Win7-64-AMD 3.3\Test', encoding='utf-8') 

...you're trying to open a directory as a file, which may (and on most non UNIX file systems will) fail.

Your other example though;

a_file = open('E:\Python Win7-64-AMD 3.3\Test\a.txt', encoding='utf-8') 

should work well if you just have the permission on a.txt. You may want to use a raw (r-prefixed) string though, to make sure your path does not contain any escape characters like \n that will be translated to special characters.

a_file = open(r'E:\Python Win7-64-AMD 3.3\Test\a.txt', encoding='utf-8') 
like image 119
Joachim Isaksson Avatar answered Sep 20 '22 03:09

Joachim Isaksson