PyInstaller 但保持 .py 文件可升级

发布于 2024-10-24 03:48:41 字数 233 浏览 3 评论 0原文

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

然而,这个应用程序可以自我升级,这是通过用通过互联网下载的新版本替换我编写的实际代码(.py 文件)来完成的。

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

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

I've managed to package my PyQt4 app as a "standalone" application on windows, it works.

However this application can upgrade itself, which is done by replacing the actual code written by me (.py files) with new versions, downloaded via the internet.

How can I tell PyInstaller do its job (putting together the DLLs, generating the launcher with the shiny icon, etc), BUT let the .py files untouched?

I need those files directly on disk, in order for the auto-update to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

葮薆情 2024-10-31 03:48:41

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


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

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")

You can change the spec file to specifically not include files by name (when building lists), then make sure these files are included - I'd have to check whether there's an option to include but not compile.


I've not tried this myself (I use pyInstaller at work but don't have it set up on my home PC) but this is the sort of thing I think should be ok:

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")
复古式 2024-10-31 03:48:41

实际上它更像是这样的:

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")

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

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

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

Actually it's more like this :

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")

As script is actually a tuple with the form :

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

You may also have to prevent files from being included in PYZ, refer to the pyz toc to see if they get included, I managed to exlude them using excludes=[myfile0] in Analysis().

北凤男飞 2024-10-31 03:48:41

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

I think the embedded interpreter in the executable will still search for .py files in the same directory and/or PYTHONPATH, py2exe uses a zip file for native python components, iirc pyinstaller embeds all of them in the executable, maybe there is an option to keep a zip like in py2exe (or not add them in the spec), then try to run the application without the files and monitor file accesses with procmon.

自由范儿 2024-10-31 03:48:41

pyinstaller 提供 --exclude 选项供您使用case ,也可以使用 .specAnalysis()excludes 参数设置要忽略的模块或包文件 。

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 .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文