简体   繁体   English

Errno 13 权限被拒绝 Python

[英]Errno 13 Permission denied Python

In python, I am currently experimenting with what I can do with open command.在 python 中,我目前正在试验我可以用open命令做什么。 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 .我在网站上寻找一些答案,我看到有人提到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. 1.我不确定这是什么 2.我不知道如何使用它,这就是我来这里的原因。

For future searchers, if none of the above worked, for me, python was trying to open a folder as a file.对于未来的搜索者,如果以上都不起作用,对我来说,python 试图将文件夹作为文件打开。

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.您的用户没有read文件的正确权限,因为您使用了open()而不指定模式。

Since you're using Windows, you should read a little more about File and Folder Permissions .由于您使用的是 Windows,您应该阅读更多关于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.此外,如果您想使用您的文件权限,您应该right-click它,选择“ Properties并选择“ Security选项卡。

Or if you want to be a little more hardcore, you can run your script as admin.或者,如果您想变得更铁杆一点,您可以以管理员身份运行您的脚本。

SO Related Questions: SO相关问题:

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.这里的问题是您的用户没有打开文件的适当权限/权限,这意味着您需要在运行该命令之前向您的 python ide 授予一些管理权限。

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.由于您是 Windows 用户,您只需要右键单击 python ide => 选择选项“以管理员身份运行” ,然后运行您的命令。

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.我试图导入一个 xlsx 文件,但 Excel 阻止我这样做。

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

In python, I am currently experimenting with what I can do with open command.在python中,我目前正在尝试使用open命令进行操作。 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 .我浏览了该网站以尝试找到一些答案,并且看到了有人提到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. 1.我不确定这是什么,并且2.我不知道如何使用它,这就是为什么我来这里。

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 .右键单击该文件,选择Properties和 select Security tab Then Users then Edit , select Users then然后Users然后Edit ,select Users然后

Check Full control检查完全控制

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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