python - How to run Kivy app using sudo? -


i writing app in kivy , part of app turn off rpi display's back-light after amount of time , turn back-light on when pressing invisible button. need use sudo python when launching app in order open file:

/sys/class/backlight/rpi-backlight/bl_power 

the problem default, error saying "no module named kivy.app" when using 'sudo python'. if add line:

defaults    env_keep += "pythonpath" 

to /etc/sudoers file allows me run app 'sudo python', none of buttons on app function. app runs, touch functionality lost. there way make work?

i'd suggest different approach: make /sys/class/backlight/rpi-backlight/bl_power writable user running python script (most pi). temporarily, can done with

sudo chmod a+w /sys/class/backlight/rpi_backlight/bl_power 

(this grants write rights users). reset @ next restart. solution write udev rule. live in /etc/udev/rules.d , on system, 99-com.rules starting point. here have in file called 98-backlight.rules:

subsystem=="backlight", program="/bin/sh -c 'chown -r root:video /sys/class/backlight && chmod -r 770 /sys/class/backlight; chown -r root:video /sys/devices/platform/rpi_backlight && chmod -r 770 /sys/devices/platform/rpi_backlight'" 

this changes owner group video , grants group write rights. user pi default member of video. need restart (or sudo udevadm control --reload-rules followed sudo udevadm trigger) activate new rule.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -