【问题标题】:Pywebview - How can one freeze pywebview applications into a smaller executable?Pywebview - 如何将 pywebview 应用程序冻结为更小的可执行文件?
【发布时间】:2021-03-03 16:25:02
【问题描述】:

我的目标:

将一个简单的 pywebview 应用程序捆绑为 Linux(特别是 Arch Linux)上的独立可执行文件(一个文件)。二进制可执行文件大小必须不大于 30MB。代码如下。

问题:

尝试编译以下应用程序(名为foobar.py)时,以及将以下命令与 pyinstaller 一起使用时:

# install my application's dependencies
pip install pywebview

# install pyinstaller
pip install pyinstaller

# install pywebview dependencies
pip install PyGObject
pyinstaller --exclude-module PyQt5 --exclude-module sympy --exclude-module numpy foobar.py

生成的可执行文件大小为 3.1 GB。

当前无效的解决方案

使用 python 虚拟环境并运行与上述相同的命令。可执行文件大小没有明显减少。

当前源代码:

foobar.py:

import webview

html = """

<!DOCTYPE html>
<html>
  <head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
      body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI",
          "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
      }
      div {
        width: 600px;
        margin: 5em auto;
        padding: 2em;
        background-color: #fdfdff;
        border-radius: 0.5em;
        box-shadow: 2px 3px 7px 2px rgba(0, 0, 0, 0.02);
      }
      a:link,
      a:visited {
        color: #38488f;
        text-decoration: none;
      }
      @media (max-width: 700px) {
        div {
          margin: 0 auto;
          width: auto;
        }
      }
    </style>
  </head>

  <body>
    <div>
      <h1>Hello World</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
        <p>
        <a href="https://example.org">More information...</a>
      </p>
    </div>
  </body>
</html>
"""

webview.create_window('Hello world', html=html)
webview.start()

【问题讨论】:

    标签: python pyinstaller pywebview


    【解决方案1】:

    这是我的解决方案:

    • 在 virtualbox 中使用 Ubuntu Linux 创建虚拟机
    • 删除/usr/local/themes 中的所有主题和/usr/local/icons 中除default/ 文件夹之外的所有图标
    • 然后,再次尝试使用 pyinstaller
    • 您的二进制文件大小约为 80 MB(小 37 倍)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 2022-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多