[英]PermissionError: Python
I was wondering if there is any way in which I can get sudo access.我想知道是否有任何方法可以获得 sudo 访问权限。 This will only work on Linux.
这仅适用于 Linux。
# get machine's username
userMachine = getpass.getuser()
# education > school's name > year
makeSchoolPath = "/home/userMachine/Education/schoolInput/str(yearCourse)"
os.makedirs(makeSchoolPath)
# last path, but also creates a leaf directory for each subject
dict2 = {}
for key, value in dict.items():
dict2 ['path' + value] = "/home/userMachine/Education/schoolInput/str(yearCourse/value"
for value2 in dict2.values():
os.mkdir(value2)
I got the error: "Exception has occurred: PermissionError [Errno 13] Permission denied: '/home/userMachine'".我收到错误消息:“发生异常:PermissionError [Errno 13] 权限被拒绝:'/home/userMachine'”。 I read that I should write
我读到我应该写
chown -R user-id:group-id /path/to/the/directory
but I don't want to mess up anything, and I'm a little bit scared of that since it means "change owner".但我不想搞砸任何事情,而且我有点害怕,因为这意味着“更换所有者”。
Thank you for reading good human being:)感谢您阅读好人:)
If you are on Linux, then just run your code with sudo python <your file name.py>
.如果您使用的是 Linux,那么只需使用
sudo python <your file name.py>
运行您的代码。
I'm pretty sure if you type “sudo python file.py” your code should have sudo perms.我很确定如果你输入“sudo python file.py”,你的代码应该有 sudo perms。 Tell me if that works.
告诉我这是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.