Errno 13 Permission denied Python

Question:

In python, I am currently experimenting with what I can do with open command. I tried to open a file, and got an error message. Here’s my code:

open(r'C:Users****DesktopFile1')

My error message was:

PermissionError: [Errno 13] Permission denied: 'C:\Users\****\Desktop\File1'

I looked on the website to try and find some answers and I saw a post where somebody mentioned chmod. 1. I’m not sure what this is and 2. I don’t know how to use it, and thats why I’ve come here.

Asked By: Jake

||

Answers:

Your user don’t have the right permissions to read the file, since you used open() without specifying a mode.

Since you’re using Windows, you should read a little more about File and Folder Permissions.

Also, if you want to play with your file permissions, you should right-click it, choose Properties and select Security tab.

Or if you want to be a little more hardcore, you can run your script as admin.

SO Related Questions:

Answered By: dot.Py

The problem here is your user doesn’t have proper rights/permissions to open the file this means that you’d need to grant some administrative privileges to your python ide before you run that command.

As you are a windows user you just need to right click on python ide => select option ‘Run as Administrator’ and then run your command.

And if you are using the command line to run the codes, do the same open the command prompt with admin rights. Hope it helps

Answered By: Gaurav Shrivastava

If you have this problem in Windows 10, and you know you have premisions on folder (You could write before but it just started to print exception PermissionError recently).. You will need to install Windows updates… I hope someone will help this info.

Answered By: PythonMan

For future searchers, if none of the above worked, for me, python was trying to open a folder as a file.

Check at the location where you try to open the file, if you have a folder with exactly the same name as the file you try to open (the file extension is part of the file name).

Answered By: Alexander

If nothing worked for you, make sure the file is not open in another program. I was trying to import an xlsx file and Excel was blocking me from doing so.

Answered By: Pengshe

The Reason most of the time is because the file security is set to not modify or write to normal users

To enable Full control to Users

right-click the file, choose Properties and select the Security tab. Then Users then Edit, select Users then

Check Full control

enter image description here

Answered By: Mohamed Fathallah
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.