经常用pyinstaller生成windows的exe程序,要设置版本号及图标非常简单,只要准备好以下的版本信息文件file_version_info.txt,还有一个图标,使用一行命令即可实现,操作流程如下:
1.版本配置文件格式如下,复制以下代码保存为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=(6, 1, 7601, 17514),
prodvers=(6, 1, 7601, 17514),
# 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=0x2,
# 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'040904B0',
[StringStruct(u'CompanyName', u'Microsoft Corporation'),
StringStruct(u'FileDescription', u'DiskPart'),
StringStruct(u'FileVersion', u'6.1.7601.17514 (win7sp1_rtm.101119-1850)'),
StringStruct(u'InternalName', u'diskpart.exe'),
StringStruct(u'LegalCopyright', u'© Microsoft Corporation. All rights reserved.'),
StringStruct(u'OriginalFilename', u'diskpart.exe'),
StringStruct(u'ProductName', u'Microsoft® Windows® Operating System'),
StringStruct(u'ProductVersion', u'6.1.7601.17514')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)
2.修改file_version_info.txt中以下字段,即可对版本及描述信息进行修改
filevers=(1, 18, 1026, 1),
prodvers=(1, 18, 1026, 1),
[StringStruct(u'CompanyName', u'Microsoft Corporation'),
StringStruct(u'FileDescription', u'DiskPart'),
StringStruct(u'FileVersion', u'6.1.7601.17514 (win7sp1_rtm.101119-1850)'),
StringStruct(u'InternalName', u'diskpart.exe'),
StringStruct(u'LegalCopyright', u'© Microsoft Corporation. All rights reserved.'),
StringStruct(u'OriginalFilename', u'diskpart.exe'),
StringStruct(u'ProductName', u'Microsoft® Windows® Operating System'),
StringStruct(u'ProductVersion', u'6.1.7601.17514')])
3.准备好要设置exe图标,比如名字为logo.ico
4.把要生成exe文件的py文件(如MainService.py)、logo.ico、file_version_info.txt放在同一个目录下,执行以下命令
pyinstaller --version-file=file_version_info.txt --icon=ico.ico --onefile --windowed MainService.py
即可生成带图标带版本信息的exe文件了
版本信息如下: