Pyinstaller未链接gtk lib

时间:2018-09-17 11:20:01

标签: python python-3.x pyinstaller gtk3

我正在尝试使用pyinstaller在Linux(Ubuntu 16.04)上冻结我的python应用程序。出于未知原因,pyinstaller在二进制文件中未包含GTK库。我收到以下错误:

ERROR:webview:GTK cannot be loaded
Traceback (most recent call last):
  File "webview/__init__.py", line 66, in import_gtk
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "/usr/local/lib/python3.4/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
  File "webview/gtk.py", line 25, in <module>
  File "gi/__init__.py", line 79, in require_version
ValueError: Namespace WebKit not available
ERROR:webview:QT cannot be loaded
Traceback (most recent call last):
  File "webview/__init__.py", line 79, in import_qt
  File "/usr/local/lib/python3.4/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
  File "webview/qt.py", line 68, in <module>
ImportError: This module requires PyQt4 or PyQt5.
Traceback (most recent call last):
  File "ui.py", line 37, in <module>
  File "webview/__init__.py", line 219, in create_window
  File "webview/__init__.py", line 152, in _initialize_imports
Exception: You must have either QT or GTK with Python extensions installed in order to use pywebview.
[23678] Failed to execute script ui
Exception in thread Thread-1:
Traceback (most recent call last):
  File "webview/__init__.py", line 177, in wrapper
  File "webview/__init__.py", line 280, in load_html
NameError: name 'gui' is not defined

二进制在具有所有依赖项的计算机上运行良好,但在干净的计算机上运行失败。我的理解是,它不会链接所有必需的库。

我使用的Dockerfile:

FROM ubuntu:xenial

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y wget python3 python3-dev python3-pip python3-gi python3-gi-cairo gir1.2-webkit-3.0

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip3 install -r requirements.txt
RUN pip3 install pyinstaller

# This image assumes that source files will be mounted in /usr/src/app
CMD [ "pyinstaller", "control-server-ui.spec", "-n", "control-server-ui" ]
#CMD [ "pyinstaller", "src/ui.py", "-n", "control-server-ui" ]

requirements.txt:

pywebview
pytest

control-server-ui.spec:

# -*- mode: python -*-
from PyInstaller.utils.hooks import collect_dynamic_libs

block_cipher = None


a = Analysis(['src/ui.py'],
             pathex=['/usr/src/app'],
             binaries=collect_dynamic_libs('webview', '.'),
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='control-server-ui',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='control-server-ui')

0 个答案:

没有答案