Here's the program:
if os.name == 'posix' and getpass.getuser() != 'root':
from subprocess import call
call(["sudo", sys.executable, os.path.realpath(__file__), "--root-install"])
> [sudo] Password for user:
PyCharm and IDEs generally don't like
getpass-like inputs. Since
sudo asks for the password in such a way, it's not runnable from a redirected IDE console.
Popen won't change anything either.
Workaround: run the
sudo command from a terminal. Example with
xterm (sorry, I don't know much about nowadays terminals):
call(["xterm","-e","sudo", sys.executable, os.path.realpath(__file__), "--root-install"])