LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Snap and Python, GTK. (https://www.linuxquestions.org/questions/linux-general-1/snap-and-python-gtk-4175623352/)

Chris.Bristol 02-08-2018 12:47 PM

Snap and Python, GTK.
 
I've created a Snap for my Python program, which runs fine and can be installed from a .deb. It has these statements:
Code:

from PIL import Image
from gi.repository import Gtk, GdkPixbuf

So I have this in the .yaml:
Code:

stage-packages:
    - python3
    - python3-pil
    - python3-gi
    - gir1.2-gtk-3.0
    - gir1.2-gdkpixbuf-2.0

It doesn’t seem to work though, trying to run the app, it errors:
Code:

chris@Dell-DXP051:~/myapp$ myapp
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 890, in _find_spec
AttributeError: 'DynamicImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "myapp.py", line 125, in <module>
    from gi.repository import Gtk, GdkPixbuf
  File "/snap/myapp/x11/usr/lib/python3/dist-packages/gi/importer.py", line 127, in find_module
    'introspection typelib not found' % namespace)
ImportError: cannot import name Gtk, introspection typelib not found
chris@Dell-DXP051:~/myapp$

I've no idea how to find out what is missing and there doesn't seem to be an active GTK forum.

Chris.Bristol 01-10-2019 02:37 PM

The PIL import works (I'd edit it out of the OP but it's not permitted).

However, nearly a year on, and I still haven't worked out how to import the GTK :( I've now tried a snapcraft.yanl copied from another post, but that doesn't work either. Surely someone must know how to create a Python+GTK Snap?

Code:

apps:
  myapp:
    command: python3 $SNAP/myapp.py
parts:
  myapp:
    source: .
    plugin: dump
 
parts:
  myapp:
    # See 'snapcraft plugins'
    plugin: python
    python-version: python3
    source: .
    build-packages: [python3-gi, python3-requests, gir1.2-gtk-3.0]
    stage-packages: [python3-gi, python3-requests, gir1.2-gtk-3.0]
    after: [desktop-gtk3]



All times are GMT -5. The time now is 11:20 PM.