我已经成功将我的 PyQt4 应用程序打包成了 Windows "独立"应用程序,它可以使用。但是该应用程序可以自我升级,通过下载通过互联网下载的新版本(.py 文件)来替换我编写的实际代码。如何告诉 PyInstaller 完成其工作(组合 DLL、生成带有闪亮图标的启动器等),但让 .py 文件不受影响?我需要直接在磁盘上保存这些文件,以使自动更新功能正常工作。
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")
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')
我认为可执行文件中的嵌入式解释器仍会在同一目录和/或PYTHONPATH中搜索.py文件,py2exe使用zip文件作为本地Python组件,如果我没记错,pyinstaller将所有组件都嵌入到可执行文件中,也许有一个选项可以像py2exe一样保留zip文件(或者不将它们添加到规范中),然后尝试在没有这些文件的情况下运行应用程序,并使用procmon监视文件访问。