Snapping a PyQt5 application

Hi,
I am trying to get a simple PyQt5 application running on snap. But it’s running into problems. The snap gets created but I get an error at runtime:

This application failed to start because it could not find or load the Qt platform plugin “xcb”
in “”.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
Reinstalling the application may fix this problem.
Aborted

This is my snapcraft.yaml:

name: testpyqt
version: '0.1'
summary: test application using PyQt5
description: |
  A test application using PyQt5 and snapcraft packaging.

grade: devel
confinement: strict
#base: core18

apps:
  testpyqt:
    command: testPyQtApp.py
    plugs: ['desktop', 'framebuffer', 'camera', 'network', 'home', 'opengl', 'x11']

parts:
  mainapp:
    after: [desktop-qt5]
    plugin: python
    python-version: python3
    source: .
    requirements: requirements.txt

  readonlydata:
    after: [mainapp]
    plugin: dump
    source: readonly
    organize:
      '*' : $SNAP_DATA/readonly/

I have run it under a container using snapcraft cleanbuild (since I am running a 18.04 box) and the snap builds fine. I get this error regarding xcb at runtime.

If I use core18 instead I get the following error:

Failed to fetch stage packages: Error downloading packages for part ‘desktop-qt5’: The package ‘appmenu-qt5’ was not found…

From what I read on the posts, using “after: [desktop-qt5]” should allow me to build an app for PyQt5. Could someone please confirm this.

I also pip installed the package and ran it inside a virtualenv in an lxc container with 16.04. Then I sshd to the machine and I was able to run the application and see the GUI. So it seems the problem is only in the actual packaging of the snap, and I have missed adding something in.

Any help would be greatly appreciated.

Here’s a PyQt5 application I snapped for reference:

This is probably due to the fact that you didn’t use the desktop-launch launcher provided by desktop-qt5 remote part, refer the following command’s output for more info:

snapcraft define desktop-qt5
  • If your snap will accept text input from foreign language users, connect the snap to the desktop-legacy interface for input method framework compatibility.
  • If your snap may access regular files under /media, you should connect the snap to the removable-media interface
1 Like

This really shouldn’t happen as the dependency is set optional: https://github.com/ubuntu/snapcraft-desktop-helpers/blob/fb943e2be372e2ce605839c20e36cad95f9a7c64/snapcraft.yaml#L147

Check your snapcraft version by running snapcraft version

Thanks a ton@Lin-Buo-Ren
That fixed the problem. Your reference snapcraft.yaml was really useful. Apparently, in addition to what you said I needed to add (would you know why that is so?):

    stage-packages:
      - python3-pyqt5

Without that the snap was building but the app wouldn’t run. In case anyone else comes looking. This is a working version of the snapcraft.yaml:

name: testpyqt
version: '0.1'
summary: test application using PyQt5
description: |
  A test application using PyQt5 and snapcraft packaging.

grade: devel
confinement: strict
#base: core18

apps:
  testpyqt:
    command: desktop-launch $SNAP/bin/testPyQtApp.py
    plugs: ['desktop', 'framebuffer', 'camera', 'network', 'home', 'opengl', 'x11', 'desktop-legacy']

parts:
  desktop-qt5:
    build-packages:
      - qtbase5-dev
      - dpkg-dev
    make-parameters:
      - FLAVOR=qt5
    plugin: make
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: qt
    stage-packages:
      - libxkbcommon0
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libqt5gui5
      - libgdk-pixbuf2.0-0
      - libqt5svg5
      - appmenu-qt5
      - locales-all
      - xdg-user-dirs

  mainapp:
    after: [desktop-qt5]
    plugin: python
    python-version: python3
    source: .
    requirements: requirements.txt
#    build-packages:
#      - python3-pyqt5
    stage-packages:
      - python3-pyqt5

  readonlydata:
    after: [mainapp]
    plugin: dump
    source: readonly
    organize:
      '*' : $SNAP_DATA/readonly/

As Lin explained the app needs to be launched with:

desktop-launch $SNAP/bin/testPyQtApp.py

and the desktop-qt5 section is corresponding output of the command:

snapcraft define desktop-qt5

Regarding the version. My snapcraft version is:

snapcraft, version 2.43.1+18.4
1 Like

Well it’s a PyQt5 application, of course it needs the library. Not sure why it is not imported by the python plugin though(assuming you’ve enumerated in the requirements.txt).

Yup. Don’t know why that’s the case. Also, for some reason, only the ‘stage-packages’ is needed and not the ‘build-packages’. So if it was a missing lib, it should have shown up for both right?

After adding the explicit desktop-qt5 section, and changing the appmenu-qt5 to try:[appmenu-qt5], and when using core18, I don’t get the message regarding 'appmenu-qt5' was not found, but a different error:

Pulling mainapp 
Failed to run '/home/awry/study/tutorials/snap/testPyQtApp/parts/mainapp/install/usr/bin/python3 -m pip': Exited with code 126.

So I think the default cloud based section for the version I am using probably doesn’t have a try in it

Shall use container based builds on 16.04 for now. Thanks a ton again for your help. I’ve been stuck on this error for days now. Should have posted sooner :slight_smile:

I think finally an understanding of snapcraft is beginning to ‘snap’ into place :wink:

Hey, it’s 2019 and I am trying to snap a pyqt5 with python3 snap and apparently things are different again and I don’t know what to do. Is there any pyqt5 python3 project that I can look on how to do it?

The docs are not helpful.

If someone prefers to answer on AskUbuntu, although my bugs have changed, this still prevails ranking reasonably high on Google when I look into it. If someone needs a code to test.

1 Like