I have a python script called main.py that imports RPi.GPIO library using import RPi.GPIO as GPIO
When I run the script using python3 main.py I get an error that states RPi.GPIO was not found. If I run main.py using sudo python3 main.py then everything runs fine.
I installed RPi.GPIO using a tar.gz file. I copied it to my /home/pi/work directory and extracted the tarball in the same directory. I then changed to the extracted directory and installed RPi.GPIO using sudo python3 setup.py install.
As I don't normally use linux I don't fully understand the permissions which I am sure is what is causing this issue. I am guessing that since I installed using sudo that the package is only available to the sudo user. The problem is I am starting this program from rc.local file and the main.py script wont run at startup with the RPi.GPIO import statement. If I remove the import statement it starts as expected. Below is the code in the rc.local file that starts the program su -l pi -c '/usr/bin/python3 /home/pi/Work/main.py &' I tried changing su to sudo but that did not work.
Is there a different way I can install RPi.GPIO or change the rc.local script to get this working? Also FYI my pi has no internet connection so I can't use APT-GET to uninstall or install the package.
Also just in case some of you wonder if the package installed properly it has. If I start python with sudo python3 I get >>>. I then type import RPi.GPIO as GPIO I get >>> again. Then I type GPIO.VERSION it displays the correct version I installed. Any help would be appreciated.
UPDATE
I did not create the code for the rc.local file and looked a little closer at it. The statement su -l pi -c '/usr/bin/python3 /home/pi/Work/main.py &' I found out changes the user from root to pi and executes the script under the pi user. So I tried changing the statement to su -l sudo -c '/usr/bin/python3 /home/pi/Work/main.py &' thinking that since I can run the main.py by using sudo python3 main.py that changing user from pi to sudo in the rc.local file would execute the file as sudo. It still does not work. I then tried removing the su command from the rc.local command and ran like this /usr/bin/python3 /home/pi/Work/main.py & but this also didn't work. Does anyone have any suggestions on how I can get this to work?