How to gain root privileges in python via a graphical sudo?

前端 未结 2 1476
悲哀的现实
悲哀的现实 2021-01-03 04:50

Part of my python program needs administrator access. How can I gain root privileges using a GUI popup similar to the gksudo command?

I only need root p

2条回答
  •  离开以前
    2021-01-03 05:26

    You have two options here:

    You will need to make the part of the program that requires root privileges a separate file and then execute the file like this:

    >>> import subprocess
    >>> subprocess.call(['gksudo','python that_file.py'])
    

    which will bring up the password prompt and run that_file.py as root

    You could also require that a program be run as root from the start and just have the program user type "gksudo python your_program.py" in the command-line from the start which is obviously not the best idea if your program is normally launched from a menu.

提交回复
热议问题