pyqt Snap 构建成功,但运行失败

pyqt Snap 构建成功,但运行失败

我使用 python3 插件构建了一个 snap。它应该打开一个 PyQt5 应用程序。snap 构建没有问题,但在安装 snap 后,在命令行中调用已安装的 python 脚本失败,并出现以下错误。

我的snapcraft.yaml

name: pyqthelloworld
version: 0.1.0
summary: pyqt hello world
description: |
 a pyqt5 python3 hello world test

confinement: strict

apps:
  pyqthelloworld:
    command: pyqthelloworld

parts:
  pyqthelloworld:
    plugin: python3
    source: git://github.com/ericoporto/pyqthelloworld
    source-type: git
    stage-packages:
      - python3-pyqt5
      - libc-bin
      - locales

我使用下面的命令构建并安装

snapcraft stage
snapcraft snap
sudo snap install pyqthelloworld_0.1.0_amd64.snap

在命令行中

$ pyqthelloworld

Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007fb8fc0ff700 (most recent call first):
Aborted (core dumped)

出了什么问题?我该如何在 snap 中调试类似的错误?

我正在使用 Ubuntu 16.04 LTS 64 位

编辑:检查编码是否存在(正确吗?)

user@pc:~/git/pyqthelloworld/snap$ find . -iname encodings
./prime/usr/lib/python3.5/encodings
./parts/pyqthelloworld/install/usr/lib/python3.5/encodings
./stage/usr/lib/python3.5/encodings

编辑2:我现在得到(snapcraft 2.15.1):

$ pyqthelloworld 
This application failed to start because it could not find or load the Qt platform plugin "xcb".

Reinstalling the application may fix this problem.
Aborted (core dumped)

只是为了澄清,没有变化,只是在同一台(并更新)的 Ubuntu 16.04 计算机上安装了较新的 snapcraft。

编辑3:

现在我添加了一个按扣文件夹,我在其中保存了 snapcraft.yaml(现在与这个问题开头的那个有点不同!)和一个小包装器来处理语言环境错误——我认为这不是必需的。

现在,当我运行已安装的 snap 的命令(pyqthelloworld)时,我得到了:

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, xcb.

Reinstalling the application may fix this problem.
Aborted (core dumped)

答案1

目前有两个与 snap 相关的 bug 会阻碍这一功能,不过两个 bug 都正在修复中:

您可以检查一下您的 snap 内容并查看是否有任何encodings模块已发货吗?

答案2

我认为你很可能是 hashbang 问题的受害者,最新版本的 snapcraft 应该可以解决这个问题,如果没有,另一个选择是使用相对路径,command这样本质上command就是command: usr/bin/pyqthelloworld

相关内容