0

Right now to get python scripts to run with user privleges in thonny with typing in this command from the command line:

sudo thonny

I can't close the command window without it closing thonny also

Is there any way to modify the shortcut in the raspian OS to automatically give super user privileges to thonny? (otherwise it can't even save files or allow python scripts to save files either)

11
  • why does thonny need super user privileges?
    – Bravo
    Dec 12, 2021 at 6:43
  • I don't know why you would WANT to run Thonny with root privileges. Generally interpreted code does not for security reasons. There is a desktop entry which executes /usr/bin/thonny %F. You could TRY including sudo in this. Previously there was a gksudo command but this is deprecated.
    – Milliways
    Dec 12, 2021 at 6:48
  • stackoverflow.com/questions/66413801/… asked and answered on stackoverflow apparently
    – Bravo
    Dec 12, 2021 at 6:49
  • this is not a Raspberry Pi specific question
    – jsotola
    Dec 12, 2021 at 6:59
  • gksudo was replaced with gksu which I think has similar functionality including sudo support.
    – user10489
    Dec 12, 2021 at 13:29

2 Answers 2

1

Put

#!/bin/bash
sudo thonny

in a file on your desktop, and set the executable permissions on it. Then you can simply double click it and select "Execute" in the dialog that opens.

In your particular use case, you might want to rethink where you store the Python files so that changing them wouldn't require sudo. E.g. you could create /home/pi/bin and add it to your PATH, or give the pi user write access to /usr/local/bin and store your Python scripts there.

3
  • 1
    You may want to use sudo -H thonny. See what does sudo -H do? for why you want that. Basically without the -H if you make any config changes while running thonny in sudo mode, the config files will be overwritten by root. After that the normal user, say pi won't have write access to its own config files!
    – user68186
    Dec 13, 2021 at 0:46
  • @user68186 I suppose the OP already has these files owned by root, because they were running the exact same command from the terminal. Dec 13, 2021 at 0:53
  • Fair enough! :)
    – user68186
    Dec 13, 2021 at 3:04
0

You can also edit the shortcut to this:

And it gives thonny super user privileges from the gui

enter image description here

sudo -H /usr/bin/thonny %F

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