简体   繁体   English

如何从 Python 以非 root 用户身份执行 bash 命令?

[英]How to execute bash commands as non root user from Python?

I am trying to use aquatone from python.我正在尝试使用 python 的 aquatone。 It works fine when I run it from VS Code or terminal using either os or subprocess.当我使用 os 或 subprocess 从 VS Code 或终端运行它时,它工作正常。 But When it is start from a parent program which is started on startup as a service.但是当它从作为服务启动时启动的父程序启动时。 It doesn't work anymore.它不再起作用了。 My guess is that it is due to the parent program being run as root.我的猜测是这是由于父程序以root身份运行。 The parent program requires root privileges.父程序需要 root 权限。
So is there any way to I can start the aquatone as a non-root user from within python??那么有什么方法可以让我从 python 中以非 root 用户身份启动 aquatone?

It depends where you've installed aquatone .这取决于您安装aquatone的位置。 By default, if you're using pip , aquatone will be installed to python/site-packages so in order to access the package and Python interpreter any app that runs Python will need to be granted root privileges. By default, if you're using pip , aquatone will be installed to python/site-packages so in order to access the package and Python interpreter any app that runs Python will need to be granted root privileges. This is the simplest way to solve the problem.这是解决问题的最简单方法。

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

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