Linux OSError: [错误 1] 不允许操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10937806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OSError: [Error 1] Operation not permitted
提问by user1357576
I am trying to run a python script which uses a binary file (xFiles.bin.addr_patched) created by a postlinker. However, I am getting this error.
我正在尝试运行一个 python 脚本,该脚本使用由 postlinker 创建的二进制文件 (xFiles.bin.addr_patched)。但是,我收到此错误。
File "abc.py", line 74, in ParseCmd
shutil.copy(gOptions.inputX, gWorkingXFile)
File "/usr/lib/python2.6/shutil.py", line 89, in copy
copymode(src, dst)
File "/usr/lib/python2.6/shutil.py", line 66, in copymode
os.chmod(dst, mode)
OSError: [Errno 1] Operation not permitted: 'myPath/xFiles.bin.addr_patched'
When I checked the permissions of this xFiles.bin, by ls-l, it shows that
当我通过 ls-l 检查此 xFiles.bin 的权限时,它显示
-rwxrwxrwx 1 nobody nogroup
I presume the error is because this file was created by some other application, the python script I am running does not have access to it. Since I am beginner wrt ubuntu, I don't really know how to fix it. Any suggestions on how to fix this?
我认为这个错误是因为这个文件是由其他一些应用程序创建的,我正在运行的 python 脚本无权访问它。由于我是 ubuntu 的初学者,我真的不知道如何解决它。对于如何解决这个问题,有任何的建议吗?
SOLVED:
解决了:
As one of the answers Suggested : chown username:groupname file name fixes this issue
作为建议的答案之一:chown username:groupname file name 解决了这个问题
采纳答案by Linuxios
You could try (from the command line, but I'm sure there's a syntax in python):
您可以尝试(从命令行,但我确定python中有语法):
sudo chown your_username:your_groupname filename
Note: The group is usually just your username.
I feel like there's something wrong with those permissions though. Read Write Execute for everyone seems to be off. How was this file created? How did it get to be created by the user nobody
?
注意:该组通常只是您的用户名。我觉得这些权限有问题。每个人的读写执行似乎都关闭了。这个文件是如何创建的?它是如何由用户创建的nobody
?
回答by Lev Levitsky
My guess is that you should be looking at the permissions for myPath
folder instead. Seems like you can't write to it, hence the problem. Try ls -l myPath/..
and see the permissions for myPath
. If that's the problem, change the permissions on the folder with chmod
.
我的猜测是您应该查看myPath
文件夹的权限。似乎您无法写入它,因此存在问题。尝试ls -l myPath/..
查看myPath
. 如果这是问题所在,请使用chmod
.
P.S. Also, see Google top result on Linux file permissions.
PS 另外,请参阅关于Linux 文件权限的Google 最高结果。
回答by Fatih Arslan
Python code to change the permission:
更改权限的 Python 代码:
from getpwnam import pwd
from getgrnam import grp
import os
uid = getpwnam("YOUR_USERNAME")[2]
gid = grp.getgrnam("YOUR_GROUPNAME")[2]
os.chown("myPath/xFiles.bin.addr_patched", uid, gid)
Run the script with sudo
and you're done.
运行脚本,sudo
你就完成了。
回答by Federico
I had this problem when running a python script on my mac (10.14 Mojave) trying to access /Users/xxx/Pictures/Photos Library.photoslibrary
.
The full solution can be found in http://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/
在我的 mac(10.14 Mojave)上运行 python 脚本试图访问/Users/xxx/Pictures/Photos Library.photoslibrary
. 完整的解决方案可以在http://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/ 中找到
Summary: Go to System Preferences > Security & Privacy > Privacy > Full Disk Access and add your IDE or python interpreter to the list.
摘要:转到系统偏好设置 > 安全和隐私 > 隐私 > 全盘访问,然后将您的 IDE 或 python 解释器添加到列表中。