8

我已经设法将我的 PyQt4 应用程序打包为 Windows 上的“独立”应用程序,它可以工作。

但是,此应用程序可以自行升级,这是通过将我编写的实际代码(.py 文件)替换为通过 Internet 下载的新版本来完成的。

我如何告诉 PyInstaller 完成它的工作(将 DLL 放在一起,生成带有闪亮图标的启动器等),但让 .py 文件保持不变?

我需要将这些文件直接放在磁盘上,以便自动更新工作。

4

4 回答 4

5

您可以将规范文件更改为明确不按名称包含文件(在构建列表时),然后确保包含这些文件 - 我必须检查是否有包含但不编译的选项。


我自己没有尝试过(我在工作中使用 pyInstaller,但没有在我的家用 PC 上设置它)但这是我认为应该没问题的事情:

a = Analysis(['main.py'])
excluded = ['myfile0.py', 'myfile1.py', 'myfile2.py']
a.scripts = [script from script in a.scripts if script not in excluded]
pyz = PYZ(a.pure)
exe = EXE(a.scripts, pyz, name="main.exe", exclude_binaries=1)
dist = COLLECT(exe, a.binaries, excluded, name="dist")
于 2011-03-20T02:32:55.240 回答
1

实际上它更像这样:

a = Analysis(['main.py'])
excluded = ['pathto\\myfile0.py', 'pathto\\myfile1.py', 'pathto\\myfile2.py']
a.scripts = [script from script in a.scripts if script[1] not in excluded]
pyz = PYZ(a.pure)
excluded_files_collect = [(f.split('\\')[-1],f,'DATA') for f in excluded]
exe = EXE(a.scripts, pyz, name="main.exe", exclude_binaries=1)
dist = COLLECT(exe, a.binaries, excluded_files_collect , name="dist")

由于 script 实际上是一个具有以下形式的元组:

('myfile0.py', 'pathto\\myfile0.py', 'PYSOURCE')

您可能还必须阻止文件包含在 PYZ 中,请参阅 pyz 目录以查看它们是否被包含,我设法在 Analysis() 中使用 excludes=[myfile0] 排除它们。

于 2013-05-17T08:13:22.783 回答
0

我认为可执行文件中的嵌入式解释器仍会在同一目录和/或 PYTHONPATH 中搜索 .py 文件,py2exe 对本机 python 组件使用 zip 文件,iirc pyinstaller 将它们全部嵌入到可执行文件中,也许有一个选项像在 py2exe 中一样保留一个 zip(或者不在规范中添加它们),然后尝试在没有文件的情况下运行应用程序并使用 procmon 监视文件访问。

于 2011-05-22T02:32:57.240 回答
0

pyinstaller provides the --exclude option for your use case , and it is also possible to set the module or package you want to ignore using the excludes parameter of Analysis() in the .spec file .

于 2018-08-20T08:59:24.213 回答