正常情况下,修改了 win-sample.py,然后变更版本文件 win-sample-version.py,用 pyinstaller 打包
...>pyinstaller -F win-sample.py --version-file win-sample-version.py
一切正常。
但是如果打包后发现版本写错了或漏改了,重新修改版本文件 win-sample-version.py,再打包查看 exe 属性发现版本信息没变!
其实是因为源代码 win-sample.py 没变,pyinstaller 认为没必要重新生成,所以也不更新版本信息了。
解决方法也很简单,删除默认的 dist
子目录(生成的 win-sample.exe 所在),再打包就必须重新生成 exe、版本信息也最新了。
附上版本文件例子
# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(ffi=FixedFileInfo(# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)# Set not needed items to zero 0.filevers=(1, 0, 2023, 119),prodvers=(1, 0, 2023, 119),# Contains a bitmask that specifies the valid bits 'flags'rmask=0x3f,# Contains a bitmask that specifies the Boolean attributes of the file.flags=0x0,# The operating system for which this file was designed.# 0x4 - NT and there is no need to change it.OS=0x4,# The general type of file.# 0x1 - the file is an application.fileType=0x1,# The function of the file.# 0x0 - the function is not defined for this fileTypesubtype=0x0,# Creation date and time stamp.date=(0, 0)),kids=[StringFileInfo([StringTable(u'000004b0',[StringStruct(u'Comments', u''),StringStruct(u'CompanyName', u'...'),StringStruct(u'FileDescription', u'window app sample'),StringStruct(u'FileVersion', u'1.0 2023-01-19'),StringStruct(u'InternalName', u'window app sampe'),StringStruct(u'LegalCopyright', u'© ... All rights reserved.'),StringStruct(u'LegalTrademarks', u''),StringStruct(u'OriginalFilename', u'win-sample.exe'),StringStruct(u'ProductName', u'win-sample'),StringStruct(u'ProductVersion', u'1.0 2023-01-19'),StringStruct(u'Assembly Version', u'1.0 2023-01-19')])]), VarFileInfo([VarStruct(u'Translation', [0, 1200])])]
)
- 首先 win-sample-version.py 是 python 语法,用 .py 是为了编辑器高亮、避免改错。其实可以任意后缀或无后缀,只要是
utf-8
编码。 filevers
和prodvers
按照 exe 格式,每部分不能超过65535
。本人喜欢用日期表示编译版本,只能把年、月日分开。虽然不能表示时间,但不会需要一天变几个版本那么疯狂吧。StringTable
下面的几个所谓的版本就是纯文本了,没有仔细尝试 exe 信息显示用的是哪个,反正改一致就行。如果真有一天变几个版本的需求,在这里加以区分。Translation
的1200
正好等于StringTable
的0x4b0
,这表示中性信息。大概在Translation
中加个语言的local id(LCID)
(比如中文2052
),然后在前面数组中加个对应的StringTable
实例,就能在对应操作系统下显示本地化的信息了——没有尝试过。- 其实
utf-8
没必要用u''
字符串格式,这个例子的最初来源大概是 python 2.x 版本时的格式——当然是按本人需要改了值。