I have written a Python script that executes several sudo-requiring actions.

How can I make the script provide a GUI prompt for the sudo password when executed?

I've tried placing gksudo -s python file.py into a bash script - running it so that it executes the above command; but that doesn't work, unfortunately...


try this inside your script 'file.py', running as normal user :

import subprocess
subprocess.call(['gksudo', 'your first sudo action here'])
subprocess.call(['gksudo', 'another bash command'])

or this inside a parent python script

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.