First python snap

Hi,
I am new to snaps thing, I have installed ubuntu core on my RPi 3 and I am trying to make a simple snap on RPi. My python is as follows:

#!/usr/bin/env python3

import RPi.GPIO as GPIO
import time

Set up PIN 0 as output

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(0, GPIO.OUT)

on = True

Every second toggle output

while True:
print (“Running”)
GPIO.output(0, on)
on = not on
time.sleep(1)

this file is saved as test-bak.py at location /test-bak and I am running sudo classic also.

My snapcraft.yaml file is as follows:

name: test-bak
version: ‘0.1’
summary: Testing
description: |
Testing snap

grade: devel # must be ‘stable’ to release into candidate/stable channels
confinement: devmode # use ‘strict’ once you have the right plugs and slots

parts:
test-bak:
source: /test-bak
plugin: python
python-version: python3
python-packages: [RPi.GPIO]

apps:
test-bak:
command: python3 test-bak.py
daemon: simple

It is giving me the following error:

(classic)bak009@localhost:/test-bak$ sudo snap run test-bak
error: cannot find current revision for snap test-bak: readlink /snap/test-bak/current: no such file or directory

Can you please use triple backticks before and after each code paste so that formatting and indentation is correct? Triple backticks are ``` and indicate “code”.

Have you successfully built your snap with snapcraft and then installed it with snap install test-bak_0.1_armhf.snap --dangerous? Were there any errors during this process?

The message that /snap/test-bak/current does not exist suggests that you haven’t installed your snap yet.

1 Like
#!/usr/bin/env python3

import RPi.GPIO as GPIO
import time

# Set up PIN 0 as output
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(0, GPIO.OUT)

on = True

# Every second toggle output
while True:
        print ("Running")
        GPIO.output(0, on)
        on = not on
        time.sleep(1)

I installed it with this command snap install test-bak_0.1_armhf.snap. There were no errors during build process. The following message is shown when I am running classic:

(classic)bak009@localhost:/test-bak$ snap run test-bak
error: cannot find current revision for snap test-bak: readlink /snap/test-bak/current: no such file or directory

and when running in normal mode it gives the following message:

bak009@localhost:~$ snap run test-bak
python3: can’t open file ‘test-bak.py’: [Errno 2] No such file or directory

Am I defining the right path. Because test-bak is in this path /test-bak when running in classic mode but when in normal mode this path does not show11