I'm having great trouble trying to build a snap for a simple python code for Rpi2.

Code I would like to put into a Snap is:

# External module imports
import RPi.GPIO as GPIO
import time

print("Hello LED")

ledPin = 9

print("Setting Broadcom Mode")
# Pin Setup:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme

GPIO.setup(ledPin, GPIO.OUT) 

print("Here we go! Press CTRL+C to exit")
while 1:
        print ("OFF");
        GPIO.output(ledPin, GPIO.LOW)
        print ("ON");            
        GPIO.output(ledPin, GPIO.HIGH)
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
   GPIO.cleanup() # cleanup all GPIO

The thing is that I don't seem to find in the documentation how to import rpi.GPIO Is this even possible?

Searched in https://github.com/ubuntu/snappy-playpen with no results

Thats the hard question. Easier question is.. How do I execute a python script with a snap? I tried putting in:

      command: sudo python helloLed.py 

and without the sudo, after it triggered error for permission.

Thank you in advance! Will be posting full example tutorial when complete!

  • You need to include RPi.GPIO in your snap, perhaps with a requirements.txt. – kyrofa Dec 13 '16 at 18:42

Add it using Python3 plugin, OP included partial snapcraft.yaml, may be need only an edit:

  plugin: python3
    - RPi.GPIO

Also it needs an access interface:

    - physical-memory-control

Then after installation the user should connect it, because that interface is not auto

sudo snap connect helloLed:physical-memory-control

Reference: Your first robot: Sharing with others [5/5]


I still have some doubts: if RPi.GPIO building from source needed. If that was the case, that it should be declared in snapcraft.yaml as a part. See the linked reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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