通过 bash 启动 python 脚本时权限被拒绝

发布于 2024-11-04 04:02:14 字数 302 浏览 1 评论 0原文

# ./scripts/replace-md5sums.py
bash: ./scripts/replace-md5sums.py: Permission denied

replace-md5sums.py 具有 chmod 600

# ls -l ./scripts/replace-md5sums.py
-rw------- 1 ubuntu ubuntu 661 2011-04-27 16:30 ./scripts/replace-md5sums.py
# ./scripts/replace-md5sums.py
bash: ./scripts/replace-md5sums.py: Permission denied

replace-md5sums.py has chmod 600

# ls -l ./scripts/replace-md5sums.py
-rw------- 1 ubuntu ubuntu 661 2011-04-27 16:30 ./scripts/replace-md5sums.py

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

杀お生予夺 2024-11-11 04:02:14

您应该能够运行脚本,输入:

$ chmod 755 ./scripts/replace-md5sums.py
$ ./scripts/replace-md5sums.py

有时,您当前登录的用户没有更改文件模式位的权限。在这种情况下,如果您有 root 密码,则可以通过以下方式更改文件权限:

$ sudo chmod 755 ./scripts/replace-md5sums.py

You should be able to run the script typing:

$ chmod 755 ./scripts/replace-md5sums.py
$ ./scripts/replace-md5sums.py

There are times where the user you are currently logged with just don't have the permission to change file mode bits. In such cases if you have the root password you can change the file permission this way:

$ sudo chmod 755 ./scripts/replace-md5sums.py
噩梦成真你也成魔 2024-11-11 04:02:14
  • 在终端中输入:chmod u+x 脚本名称,末尾带有“.py”扩展名。
  • 请记住,u 代表用户,x 代表对文件的读取、写入和执行操作。
  • 还要记住,必须位于 Python 脚本顶部的行是: #!/usr/bin/python3.9 在 root 上,您可以轻松识别 python 版本和路径是什么。
  • 现在重新执行一次。
  • In the terminal enter: chmod u+x script name with the '.py' extension in the end.
  • Remember, u stands for user and x read, write and execute actions to the file.
  • Keep in mind as well the line which must go on top of your Python script which is: #!/usr/bin/python3.9 Going on root you can easily identify what the python version and path is.
  • Now re-execute it again.
季末如歌 2024-11-11 04:02:14

使用“exec”选项挂载 Windows 分区 - 在某些发行版上默认为“noexec”。

Mount your Windows partition with "exec" option - on some distros it's "noexec" by default.

一抹淡然 2024-11-11 04:02:14

我解决了我的问题。它只是解释器从第一行读取的 python 版本。删除版本号对我来说是这样,即

#!/usr/bin/python2.7 --> #!/usr/bin/python

I solved my problem. it's just the version of python which the interpreter reads off the first line. removing to version numbers did it for me, i.e.

#!/usr/bin/python2.7 --> #!/usr/bin/python
小苏打饼 2024-11-11 04:02:14

试试这个

python ./scripts/replace-md5sums.py

Try this

python ./scripts/replace-md5sums.py
掩饰不了的爱 2024-11-11 04:02:14

我是 Ubuntu 用户,当我尝试通过 bash 脚本运行 python 脚本而文件位于 NTFS 分区中时(即使使用 su 也不起作用),我也遇到了同样的问题我把它移回家(ext4)然后它就工作了。

I'm a Ubuntu user and I had the same issue, when I was trying to run python script through a bash script while files were located in a NTFS partition (even with su didn't work) then I've moved it home (ext4) then it worked.

要走就滚别墨迹 2024-11-11 04:02:14

好的,首先检查您的 python 脚本是否位于正确的目录中。
在网上,他们说运行命令:

python3 your_file_name.py

但它不起作用。
然而对我有用的是:

python -u my_file_name.py

Okay, so first of all check if you are in the correct directory where your python script is located.
On the net, they say to run the command :

python3 your_file_name.py

But it doesn't work.
What worked for me however was:

python -u my_file_name.py
狼亦尘 2024-11-11 04:02:14
#strace ./scripts/replace-md5sums.py
#strace ./scripts/replace-md5sums.py
若言繁花未落 2024-11-11 04:02:14

检查身份证。它可能具有 root 权限。

因此,输入 su ,然后执行脚本 ./scripts/replace-md5sums.py

有用。

Check for id. It may have root permissions.

So type su and then execute the script as ./scripts/replace-md5sums.py.

It works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文