使用pyi-set_version为PyInstaller打包出来的程序附加版本信息
本文将讲述如何使用pyi-grab_version获取版本信息的模板文件,以及使用pyi-set_version为打包好的程序附加版本信息。
当然了,在开始前,需要你已经安装好了PyInstaller这个工具。
如果已经安装,你可以在Python的安装目录,Scripts 文件夹下找到 pyi-grab_version 和pyi-set_version 这两个工具。
使用pyi-grab_version创建版本信息模板文件
这里我以 QQ.exe 为例子;
在CMD环境下执行命令 pyi-grab_version QQ.exe完整路径名
(小技巧:可直接将QQ.exe拖曳到CMD窗口获得完整路径);

执行完后,我们会在pyi-grab_version.exe 文件的目录下获得一个 file_version_info.txt 文件。
file_version_info.txt 文件内容如下:
# 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=(9, 3, 3, 27011),
prodvers=(9, 3, 3, 27011),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=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=0x40004,
# 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 fileType
subtype=0x0,
# Creation date and time stamp.
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'080404b0',
[StringStruct(u'CompanyName', u'Tencent'),
StringStruct(u'FileDescription', u'腾讯QQ'),
StringStruct(u'FileVersion', u'9.3.3.27011'),
StringStruct(u'LegalCopyright', u'Copyright (C) 1999-2020 Tencent. All Rights Reserved'),
StringStruct(u'ProductName', u'腾讯QQ'),
StringStruct(u'ProductVersion', u'9.3.3.27011')])
]),
VarFileInfo([VarStruct(u'Translation', [2052, 1200])])
]
)
将文件中对应的值修改成自己需要的,现在我们将这些版本信息附加到我们的打包程序中。
方法 1:在打包时加入版本信息
在使用 PyInstaller 打包时加入选项 --version-file [后跟版本信息文件路径] ,例:
pyinstaller -F -w --version-file c:\myVersionInfo.txt c:\main.py
方法 2:使用 pyi-set_version 为已经打包好的EXE文件添加版本信息
为已经打包好的EXE文件添加或修改版本信息用这种方法;
pyi-set_version c:\myVersionInfo.txt c:\myApp.exe
最终效果图:
