PyInstaller but keeping .py files upgradeable

倖福魔咒の 提交于 2019-12-20 14:44:38

问题


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.


回答1:


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



回答2:


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().




回答3:


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.




回答4:


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 .



来源:https://stackoverflow.com/questions/5366100/pyinstaller-but-keeping-py-files-upgradeable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!