Warpinator snap not working. When trying to run the snap fails with error message, "ModuleNotFoundError: No module named 'gi'"

I added extensions under apps as,

extensions: [gnome-3-34]

Nil joy. Snap builds successfully but still doesn’t launch with “no module name ‘gi’” error as mentioned above.

looks like you need to mangle PYTHONPATH to point to the right place …

alternatively you could pull all the python modules from pip witn a separate python part, that should set PYTHONPATH for you…

I had read your suggestion regarding this elsewhere in the forum and had tried adding PYTHONPATH but does not help. I have added following line.

apps:
  warpinator:
    extensions: [gnome-3-28]
    command: bin/warpinator
    environment:
      PYTHONPATH: $SNAP/usr/lib/python3.6/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

It goes past ‘gi’ but then errors saying no module named ‘warpinator’.

I believe this was just fixed by @hellsworth and merged into snapcraft two days ago. https://github.com/snapcore/snapcraft/pull/3270/files

gi should come from the gnome-platform snap, which means you should be OK with “$SNAP_DESKTOP_RUNTIME/usr/lib/python3.6/site-packages” in your PYTHONPATH.

Or sudo snap refresh snapcraft --edge and see if it works for you :smiley:

1 Like

@hellsworth The above snap is using 3-28, and for that case the path may need to be $SNAP_PLATFORM/usr/lib/python3/dist-packages/gi in that case.

@saivinob if trying with edge, using gnome-3-34

1 Like

@cjp256, thank you for the suggestion and the link. I tried to build with gnome-3-34, snap completes build as before but on launching shows segmentation fault. Please see complete message below.

sai@sai-mintstick:~/snapcrafts/warpinator$ warpinator 
Warning: Schema “org.gnome.system.locale” has path “/system/locale/”.  Paths starting with “/apps/”, “/desktop/” or “/system/” are deprecated.
Warning: Schema “org.gnome.system.proxy” has path “/system/proxy/”.  Paths starting with “/apps/”, “/desktop/” or “/system/” are deprecated.
Warning: Schema “org.gnome.system.proxy.http” has path “/system/proxy/http/”.  Paths starting with “/apps/”, “/desktop/” or “/system/” are deprecated.
Warning: Schema “org.gnome.system.proxy.https” has path “/system/proxy/https/”.  Paths starting with “/apps/”, “/desktop/” or “/system/” are deprecated.
Warning: Schema “org.gnome.system.proxy.ftp” has path “/system/proxy/ftp/”.  Paths starting with “/apps/”, “/desktop/” or “/system/” are deprecated.
Warning: Schema “org.gnome.system.proxy.socks” has path “/system/proxy/socks/”.  Paths starting with “/apps/”, “/desktop/” or “/system/” are deprecated.
Segmentation fault (core dumped)

I tried,

  1. snapcraft stable + gnome-3-34, same error of module ‘gi’ not found
  2. snapcraft stable + gnome-3-34 + environment set, seg faults
  3. snapcraft edge + gnome-3-34, seg faults
  4. snapcraft edge + gnome-3-34 + environment set, seg faults
  5. did snapcraft clean and then rebuilt with, snapcraft edge + gnome-3-34, seg faults.

By environment set, I mean this,

environment:
      PYTHONPATH: $SNAP_DESKTOP_RUNTIME/usr/lib/python3.6/site-packages:$SNAP/lib/python3.6/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

and also,

environment:
      PYTHONPATH: $SNAP/lib/python3.6/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

When I check, /snap/warpinator/current/gnome-platform, it is empty.

sai@sai-mintstick:~/snapcrafts/warpinator$ ls -la /snap/warpinator/current/gnome-platform/
total 0
drwxr-xr-x  2 root root   3 Oct  3 09:58 .
drwxr-xr-x 11 root root 156 Oct  3 10:00 ..

Following is the snapcraft.yaml I am using.

name: warpinator
base: core18
version: '1.0.8'
summary: Share files across the LAN
description: |
  Share files across the LAN.

grade: devel
confinement: devmode

package-repositories:
  - type: apt
    ppa: clementlefebvre/grpc

parts:
  mint-grpc:
    plugin: nil
    build-packages:
    - software-properties-common
    - apt-utils
    - python3-grpcio
    - python3-grpc-tools
    - python3-protobuf
    #stage-packages:
    #- python3-grpcio
    #- python3-grpc-tools
    #- python3-protobuf
    
  pymodules:
    source: .
    plugin: python
    python-version: python3
    stage-packages:
    - python3-gi
    - python3-setproctitle
    - python3-xapp
    - python3-zeroconf
    - python3-cryptography
    - python3-nacl
    - python3-netifaces
    - python3-packaging
    - python3-grpc-tools
    - python3-grpcio
    - python3-protobuf
    after: [mint-grpc]
   
  warpinator:
    source: .
    plugin: meson 
    meson-parameters: [ --prefix=/usr ]
    build-packages:
    - appstream
    - gcc
    - gettext
    - gnome-pkg-tools
    - meson
    - policykit-1
    - gobject-introspection
    stage-packages:
    - gir1.2-glib-2.0
    - gir1.2-gtk-3.0
    - gir1.2-xapp-1.0
    after: [pymodules]

apps:
  warpinator:
    extensions: [gnome-3-34]
    command: bin/warpinator
    #environment:
    #  PYTHONPATH: $SNAP/lib/python3.6/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
    #  PYTHONPATH: $SNAP_DESKTOP_RUNTIME/usr/lib/python3.6/site-packages:$SNAP/lib/python3.6/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
    #plugs: ['home','removable-media','network','network-bind']

try adding:

layout:
  /usr/bin/python3.6:
    bind-file: $SNAP/usr/bin/python3.6

that should make the segfault go away, i guess the python code runs #!/usr/bin/python3 instead of #!/usr/bin/env python3 (which would pick the interpreter from inside the snap)… to make such code use the shipped interpreter instead of the hosts one…

Yes, the python code are all using #!/usr/bin/python3 as you guessed. However adding the layout has not changed the situation. Without environment set, it seg faults. With environment set, it just says no module ‘warpinator’ (goes past ‘gi’).

I think I saw python seem to be symlink to python2 instead of python3 in the base environment. I did not take screenshot. Is that normal, perhaps for Bionic? Does that affect? Also, is it normal that gnome-platform is an empty folder?

Yes. You can see it if you enter the context of your snap: snap run --shell warpinator

It looks like a mismatch between the glib libs staged in your snap vs. the ones in the gnome desktop.

$ snap run --shell warpinator
$ python3 -c 'from gi.repository import Gio, GLib'
Segmentation fault (core dumped)

$ LD_LIBRARY_PATH=$SNAP/gnome-platform/lib/x86_64-linux-gnu:$SNAP/gnome-platform/usr/lib/x86_64-linux-gnu:$SNAP/gnome-platform/usr/lib:$SNAP/gnome-platform/lib:$SNAP/gnome-platform/usr/lib/x86_64-linux-gnu/dri:$LD_LIBRARY_PATH

$ python3 -c 'from gi.repository import Gio, GLib'
...OK.

$ $SNAP/usr/bin/warpinator
No module named 'warpinator'

That last error is because there is no warpinator library found in the snap. Probably an easy fix once we sort out how to resolve the segfault… :smiley:

LD_LIBRARY_PATH is modified late, so we can’t just set the order in the app’s environment. Is there an established pattern to address this @kenvandine @hellsworth @sergiusens ?

Remove the following stage-packages which conflict with the gnome platform snap:

If I do this :point_up_2:, I am getting following error.

sai@sai-mintstick:~/snapcrafts/warpinator$ warpinator
/snap/warpinator/x3/gnome-platform/usr/lib/x86_64-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0: symbol lookup error: /snap/warpinator/x3/gnome-platform/usr/lib/x86_64-linux-gnu/libgtk-3.so.0: undefined symbol: g_mount_operation_set_is_tcrypt_hidden_volume
ERROR: /snap/warpinator/x3/gnome-platform/usr/lib/x86_64-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0 exited abnormally with status 127
Traceback (most recent call last):
  File "/snap/warpinator/x3/usr/bin/warpinator", line 7, in <module>
    from gi.repository import Gio, GLib
ModuleNotFoundError: No module named 'gi'

My latest snapcraft.yaml is as below:

name: warpinator
base: core18
version: '1.0.8'
summary: Share files across the LAN
description: |
  Share files across the LAN.

grade: devel
confinement: devmode
license: GPL-3.0+

package-repositories:
  - type: apt
    ppa: clementlefebvre/grpc

layout:
  /usr/bin/python3.6:
    bind-file: $SNAP/usr/bin/python3.6

parts:
  pymodules:
    source: .
    plugin: python
    python-version: python3
    build-packages:
    - python3-grpcio
    - python3-grpc-tools
    - python3-protobuf
    stage-packages:
    - python3-grpc-tools
    - python3-grpcio
    - python3-protobuf
    #- python3-gi
    - python3-setproctitle
    - python3-xapp
    - python3-zeroconf
    - python3-cryptography
    - python3-nacl
    - python3-netifaces
    - python3-packaging
   
  warpinator:
    source: .
    plugin: meson 
    meson-parameters: [ --prefix=/usr ]
    build-packages:
    - software-properties-common
    - apt-utils
    - appstream
    - gcc
    - gettext
    - gnome-pkg-tools
    - meson
    - policykit-1
    - gobject-introspection
    stage-packages:
    #- gir1.2-glib-2.0
    #- gir1.2-gtk-3.0
    #- gir1.2-xapp-1.0
    #- gir1.2-gobject-2.0
    #- gir1.2-cairo-1.0
    - gettext
    after: [pymodules]

icon: snap/gui/org.x.Warpinator.png

apps:
  warpinator:
    command: usr/bin/warpinator
    extensions: [gnome-3-34]
    #environment:
    #  PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$SNAP/usr/lib/$ARCH:$PYTHONPATH
    #plugs: ['home','removable-media','network','network-bind']

In past couple of days, I scanned snapstore for python+gtk snaps to see how they have written snapcraft.yaml (if it’s on snapstore, obviously it works!). I found two: bzoing and kfit. I tried to create snap for both locally and snapped successfully. They also run fine. They had used desktop-launch/desktop-helpers method. To see, if it is an issue with extensions method, I changed the snapcraft.yaml file to use extensions. Still both apps snapped and work correctly. I also created snap for another python+gtk app called ‘exaile’, this time creating snap from scratch. It also built and worked OK (except I did not have icons for any theme other than Ubuntu Mono/Humanity). Issue is only with warpinator (mint tools?!).

As much as I could see, all of the other projects used /usr/bin/env python3 while warpinator uses /usr/bin/python3 as @ogra had asked me before. But then, with same, I was able to create a .deb package and run without issue. I also installed flatpak version and that also works OK. So, the problem is on the snap-side.

I reproduced your issue with the yaml you just posted.

Here is the yaml I tested yesterday, that got further.

name: warpinator
base: core18
version: '1.0.8'
summary: Share files across the LAN
description: |
  Share files across the LAN.

grade: devel
confinement: devmode

package-repositories:
  - type: apt
    ppa: clementlefebvre/grpc

parts:
  mint-grpc:
    plugin: nil
    build-packages:
    - software-properties-common
    - apt-utils
    - python3-grpcio
    - python3-grpc-tools
    - python3-protobuf
    
  pymodules:
    source: .
    plugin: python
    python-version: python3
    stage-packages:
    - python3-setproctitle
    - python3-xapp
    - python3-zeroconf
    - python3-cryptography
    - python3-nacl
    - python3-netifaces
    - python3-packaging
    - python3-grpc-tools
    - python3-grpcio
    - python3-protobuf
    after: [mint-grpc]
   
  warpinator:
    source: .
    plugin: meson 
    meson-parameters: [ --prefix=/usr ]
    build-packages:
    - appstream
    - gcc
    - gettext
    - gnome-pkg-tools
    - meson
    - policykit-1
    - gobject-introspection
    after: [pymodules]

apps:
  warpinator:
    extensions: [gnome-3-34]
    command: bin/warpinator

Staging gettext looks like the culprit in your case. You should also be able to drop the layout.

I tried as suggested. There are no seg faults or earlier error messges now but am back to plain ‘no module named ‘gi’’ error.

Traceback (most recent call last):
  File "/snap/warpinator/x3/usr/bin/warpinator", line 7, in <module>
    from gi.repository import Gio, GLib
ModuleNotFoundError: No module named 'gi'

Can you try a snapcraft clean in case something got messed up? I don’t know why you would still be getting that result…

I did that. Actually, each time I am building now, I am starting with snapcraft clean just to be sure. Hasnt’ made any difference.

I tried to build using desktop-gtk3/desktop-lauch method (not using extension). Builds fine but same error for ‘gi’. I then ran the snap run --shell command you showed before. I get following. Hope it helps.

sai@sai-mintstick:~/snapcrafts/warpinator$ snap run --shell warpinator
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

sai@sai-mintstick:/home/sai/snapcrafts/warpinator$ python3 -c 'from gi.repository import Gio, Glib'
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 888, 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 "<string>", line 1, in <module>
  File "/snap/warpinator/x12/usr/lib/python3/dist-packages/gi/importer.py", line 127, in find_module
    'introspection typelib not found' % namespace)
ImportError: cannot import name Gio, introspection typelib not found

Did you mean, it worked for you? You could launch warpinator GUI?

No, but I had No module named 'warpinator'. Which is because of how warpinator installs the python module.

Getting past that, I now get ValueError: Namespace XApp not available. Which brings us back around to the GTK mismatch because we need gir1.2-xapp-1.0:frowning_face:

Here’s what I’m working from: https://github.com/cjp256/warpinator/blob/snap-support/snap/snapcraft.yaml

Hopefully @kenvandine @hellsworth can help us out… should we be using desktop helpers for this case?

I actually have a working warpinator snap but it’s published in the edge channel and unlisted because it’s not fully functional yet. It is possible to send files back and forth, but there’s some other issues I’m working on.

Screenshot%20from%202020-10-08%2013-48-03

Screenshot%20from%202020-10-08%2013-47-34

Oh…thank you @popey. Some good news at last. Would you please share your yaml file so I can compare and build locally? I want to learn.

Here’s what I’m currently using. It just consumes the pre-built deb directly out of the mint archives. This isn’t ideal. I did try building from source in the past, on 18.04, but there were a bunch of newer python packages needed. I moved to 20.04, but it was just as painful. So I switched to this method.

name: warpinator
base: core20
version: '1.0.8'
summary: Share files across the LAN
description: Allows simple local network file sharing.

grade: stable
confinement: strict

slots:
  # for GtkApplication registration
  snap-store:
    interface: dbus
    bus: session
    name: org.x.Warpinator

parts:
  desktop-gtk3:
    build-packages:
    - build-essential
    - libgtk-3-dev
    make-parameters:
    - FLAVOR=gtk3
    plugin: make
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: gtk
    stage-packages:
    - libxkbcommon0
    - ttf-ubuntu-font-family
    - dmz-cursor-theme
    - light-themes
    - adwaita-icon-theme
    - gnome-themes-standard
    - shared-mime-info
    - libgtk-3-0
    - libgdk-pixbuf2.0-0
    - libglib2.0-bin
    - libgtk-3-bin
    - unity-gtk3-module
    - libappindicator3-1
    - locales-all
    - xdg-user-dirs
    - ibus-gtk3
    - libibus-1.0-5
    - fcitx-frontend-gtk3
  warpinator: 
    source: http://packages.linuxmint.com/pool/backport/w/warpinator/warpinator_$SNAPCRAFT_PROJECT_VERSION+ulyana_all.deb
    plugin: dump
    stage-packages:
      - libc-ares2 
      - python3-pip
      - python3
      - python3-cryptography
      - python3-zeroconf
      - python3-xapp
      - python3-setproctitle
      - python3-netifaces
      #- libglu1-mesa
      - python3-nacl
      - python3-grpcio
      - gir1.2-xapp-1.0
      - python3-gi
      - gobject-introspection
      - gir1.2-gtk-3.0
      - gir1.2-glib-2.0
      - python3-protobuf
      - python3-packaging
    override-pull: |
      snapcraftctl pull
      sed -i 's|/usr/libexec|/snap/warpinator/current/usr/libexec|' usr/bin/warpinator
    override-build: |
      snapcraftctl build
      echo "#!/bin/sh" > $SNAPCRAFT_PART_INSTALL/warpinator
      #echo "/snap/warpinator/current/usr/bin/python3 /snap/warpinator/current/usr/libexec/warpinator/warpinator.py" >> $SNAPCRAFT_PART_INSTALL/warpinator
      echo "/usr/bin/python3 /snap/warpinator/current/usr/libexec/warpinator/warpinator.py" >> $SNAPCRAFT_PART_INSTALL/warpinator
      chmod +x $SNAPCRAFT_PART_INSTALL/warpinator
      sed -i 's|config.pkgdatadir|"/snap/warpinator/current/usr/share/warpinator"|g' $SNAPCRAFT_PART_INSTALL/usr/libexec/warpinator/warpinator.py
      sed -i 's|config.pkgdatadir|"/snap/warpinator/current/usr/share/warpinator"|g' $SNAPCRAFT_PART_INSTALL/usr/libexec/warpinator/prefs.py

apps:
  warpinator:
    command-chain: [bin/desktop-launch]
    command: warpinator
    environment:
      LD_LIBRARY_PATH: "$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio:$LD_LIBRARY_PATH"
      DISABLE_WAYLAND: 1
      XDG_CURRENT_DESKTOP: Unity
      TMPDIR: $XDG_RUNTIME_DIR
      XDG_DATA_HOME: $SNAP_USER_COMMON
      HOME: $SNAP_USER_COMMON
      GSETTINGS_SCHEMA_DIR: $SNAP/usr/share/glib-2.0/schemas
      PYTHONPATH: $SNAP/usr/lib/python3/dist-packages
      GI_TYPELIB_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/girepository-1.0
    plugs:
      - avahi-control
      - audio-playback
      - x11
      - opengl
      - desktop
      - desktop-legacy
      - network
      - network-bind
      - unity7
      - wayland
      - gsettings
      - home
      - removable-media
1 Like

Thank you @popey. I did install your warpinator snap from beta channel and looked at snap.yaml. I saw you used core20 but when I tried it with extensions method, it said that extension gnome-3-34 is not supported yet, so I went with desktop-helpers method. Since snap.yml did not have ‘parts’, I combined the ‘environment’, ‘command-chain’ from your file and ‘parts’ from my file. Still doesn’t work (while your snap works). Will use your snapcraft.yaml file to locally build and check.

BTW, there is a interesting discussion regarding python plugin, which may help me. Will check that as well.