【发布时间】: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