How to setup python snaps

So I am newer to Snapcraft, however I have been having this issue, despite following examples and tutorials so I figured I would ask here.

EDIT: So it looks like I can’t build any snap. It always throws the error that the first thing in the app command line doesn’t exist. Tried building the example liquidctl project and had the same issue.

Original Problem:

Machine setup: So I am on a windows machine, running ubuntu in a VM to compile the snap. Sadly work has not given me a ubuntu dev machine. Our deployments are on linux machines (hence the need for a snap), but they gave me a windows machine.

Snap Problem: Have a file ( that is normally launched as “python3 -m main” and we want to make it into a snap.

So far I have this as my snap:

name: asdf
version: '4.0.0'
summary: asdf
description: |
    qweradsf - blah-etc...
grade: devel
confinement: devmode
base: core22

    plugin: python
    source: .
      - pyserial
      - ftputil

    command: usr/bin/python -m main
      PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:${SNAP}/usr/local/lib

For the command part I have tried all the combinations below

command: usr/bin/python -m main
command: /usr/bin/python -m main
command: /bin/python -m main
(also tried the above eith /usr/lib/python path)
command: python -m main
command: python3 -m main

When it goes to pack the snap file, I will get the error that the first argument - usr, bin, python, python3 - path doesn’t exist. Also tried adding PYTHONPATH. Nothing seems to work.

How do I call this python code? Do I need a source? Examples I saw didn’t use a source for the plugin (just had the . ), so I have been leaving that part mostly alone.

Try bin/python3 (no leading slash).

Is there no main executing file? If it’s there then just locate to it to the command. If it’s in usr/bin, then

command: usr/bin/main

Guess this will work.

So bin/ did the trick. Thank you @ goodsoftworx!

I think I had a secondary issue as well. Tried building sample projects with the same PATHING errors -
snapcraft clean on the project did wonders.

1 Like