SyntaxError: Non-ASCII character '\xe2' for python snap

Hi All,

When tried to run the python snap created, it gives below error
SyntaxError: Non-ASCII character ‘\xe2’ in file ultra2_master_armhf.snap on line 1, but no encoding declared; see for details

I have added following comments in python program as per the details mentioned in error, but still getting the error.

-- coding: --



vim: set fileencoding= :

I have tried to run “sudo python .snap” command after installing snap.
Please suggest

Thanks & Regards,

It looks like you’re trying to execute the ultra2_master_armhf.snap file directly. This won’t work because it isn’t an executable file. The .snap file is a squashfs filesystem which gets mounted by snapd when you run snap install ultra2_master_armhf.snap --dangerous. Once installed you execute the command you have exposed via your snapcraft.yaml through, as an example, either /snap/bin/ultra2 or snap run ultra2.

Thanks for the help.

I have executed the command “sudo snap install *.snap --devmode --dangerous” before running snap.
When tried to run the snap using “sudo python”, it gives below error
python: can’t open file ‘’: [Errno 2] No such file or directory

Find below is my snapcraft.yaml file

name: ultra2
version: master
summary: ultra2
description: |
This snap reads distance from the obstacle.

grade: devel
confinement: devmode

command: sudo python
plugs: [gpio-memory-control]

plugin: python
python-version: python3
python-packages: [RPi.GPIO]

first of all please put pasted code between triple backticks so it gets formatted correctly (else we cant say if the indendation of your yaml is correct) …

you would have to put sudo inside your snap for this to work, better drop the sudo call there and have the user use sudo when calling your command.

this is not how you run a command from a snap:

    command: sudo python
    plugs: [gpio-memory-control]

the command you create in your snapcraft.yaml is called “ultra2” so to run it you would do:

snap run ultra2

(and if your command needs sudo you prefix this with the sudo call)

Thanks for your help.

I have implemented the changes suggested, but getting the below error when run “sudo snap run ultra2”

error: cannot find current revision for snap ultra2: readlink /snap/ultra2/current: no such file or directory

Is this the yaml file issue or git file structure?

Thanks & Regards,

what is the output of snap version (so we can see what components are involved in snap execution on your system) ?

also, does snap list show your snap ?

Yes, snap list shows the snaps
ultra2 master x4 - - devmode

The snap version is as below
snap 2.32.9
snapd 2.33
series 16
kernel 4.4.0-1091-raspi2

The python program “sudo python” is running fine and gives the distance information
Distance: 1.73cm
Distance: 6.12cm
Distance: 2.40cm
Distance: 6.15cm
Distance: 6.21cm

When it is bundled with snap, then getting some issue.