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.
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 .
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.
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With