当我尝试从 bash 执行 python 脚本时权限被拒绝?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26619272/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:46:12  来源:igfitidea点击:

Permission denied when i try to execute a python script from bash?

pythonbashshellpython-2.7

提问by tumbleweed

I downloaded a python script from the web and when i try to execute it from bash it throws a exception:

我从网上下载了一个 python 脚本,当我尝试从 bash 执行它时,它抛出一个异常:

User:python_script user$ ./python_script.py -n some_parameter -b

User:python_script user$ ./python_script.py -n some_parameter -b

The output is the following:

输出如下:

-bash: ./python_script.py: Permission denied

the file all ready has: #!/usr/bin/pythonat the top of the script. How can i solve this?

准备好的文件有:#!/usr/bin/python在脚本的顶部。我该如何解决这个问题?

采纳答案by NPE

You need to add execute permissions like so:

您需要像这样添加执行权限:

chmod u+x python_script.py

This assumes that the script is owned by you. If it isn't, you might need to change the group/other execute permissions or chownthe file as appropriate.

这假定脚本归您所有。如果不是,您可能需要根据需要更改组/其他执行权限或chown文件。