简体   繁体   中英

Errno 13 Permission denied Python

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\****\Desktop\File1')

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.

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).

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:

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

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.

如果您在 Windows 10 中遇到此问题,并且您知道您对文件夹有前提(您之前可以写,但它最近才开始打印异常 PermissionError)。您将需要安装 Windows 更新......我希望有人能帮助解决这个问题信息。

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\****\Desktop\File1')

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.

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM