I'm trying to use the RPi.GPIO Library in a python-script with root-privileges. I essentially need to run it with sudo because other stuff in my script require root-privileges.
When i try the following code without sudo, everything works fine:
import RPi.GPIO as GPIO
But as soon as i try to run it with sudo, im getting the following error:
ModuleNotFoundError: No module named 'RPi'
I have tested the rest of my script, it is working fine without the GPIO-Controlling. What i find especially interesting is that seemingly every other post is about getting GPIO to run without root privileges, and im trying to achieve the opposite and couldnt find any information about it.
EDIT:
The suggested Installation process for the Module via pip3 was already successfully done before i ran into this problem. I have tested other scripts using the module and running without sudo, works perfectly fine.
SOLUTION:
i reinstalled the Module while beeing logged in as root.
sudo
leaves only a few variables in the environment. Perhaps you need to copy over PYTHONPATH or similar.sudo
changes things in that all of your commands are actually run byexec
.