Python + Gtk+3 Snap

I have a Debian .deb file which runs my Python/Gtk+3 application.I have also successfully created a python wheel and a pip installation archive. I would like to create a Snap. After dozens of failed attempts, I have copied the code below from another thread with a similar title and commented out some bits I think are irrelevant, to run my application from a desktop file. The process succeeds, but doesn’t create a .snap file. What have I missed out?

version: '0.0.1'
summary: Test
description: Test
confinement: strict
#-------------------------------------------------------------------------------
apps:
  g:
    command: desktop-launch $SNAP/g.desktop
    plugs: [home]

parts:
    g:
        plugin: python
        source: .
        stage-packages:
            - python3-distutils-extra
            - python3-gi
            #- gir1.2-unity-5.0
            #- gir1.2-notify-0.7
            - gir1.2-gtk-3.0
            #- gir1.2-pango-1.0
        after: [desktop-gtk3]
#        stage:
#            - -usr/share/pkgconfig # also in desktop-gtk3
#            - -usr/share/mime      # also in desktop-gtk3
1 Like

I am having the same issue with my app. In my case, when I do not use the gtk extension in

apps:
  simple-pwgen:
    command: bin/simple-pwgen
    extensions: [gnome-3-38]

I get a .snap file. But post install, It fails saying

Traceback (most recent call last):
  File "/snap/simple-pwgen/x24/bin/simple-pwgen", line 5, in <module>
    from SimplePwgen.main import start_SPGCli
  File "/snap/simple-pwgen/x24/lib/python3.8/site-packages/SimplePwgen/main.py", line 7, in <module>
    from SimplePwgen.gui import run_SPGwindow
  File "/snap/simple-pwgen/x24/lib/python3.8/site-packages/SimplePwgen/gui.py", line 33, in <module>
    gi.require_version("Gtk", "3.0")
  File "/snap/simple-pwgen/x24/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available

Apparently, after searching a lot of posts, I found that the gnome extension has has always prevented builds using Python on core20. And there are no bugs reported on launchpad.

1 Like

Your post was the first reply to my original post for 4 years. I have given up on Snap and created a Flatpak instead - that’s now released on Flathub.

1 Like

When I was searching for Python + GTK, I came along a lot of post having the same issue. And all the cases, the solution is not so beginner friendly. I wonder why there has not been a bug reported on Launchpad. Since there are no bugs reported on launchpad, I am thinking of creating one and hoping that they would fix this.

1 Like

Hi! @ChrisOfBristol, I have successfully created a snap of my python app. What I was missing is proper PYTHONPATH. I’ll post a detailed code with explanation as comments.

1 Like

I’m glad you’ve finally succeeded! I’m committed to Flatpak now, but I had a look at your Snap file to see whether it might be worth considering another attempt at a Snap. Complicated or what! I don’t think it would be practical for me - there seem to be a lot of bits to do with GTK in it and I’m using GTK4 not Gtk3+. I have dependencies on other packages as well - although I could have created a cut-down version without them.