安装pyinstaller
python.exe -m pip install pyinstaller
pyinstaller 帮助
PS C:\Python37> pyinstaller.exe -h
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
[--add-data <SRC;DEST or SRC:DEST>]
[--add-binary <SRC;DEST or SRC:DEST>] [-p DIR]
[--hidden-import MODULENAME]
[--additional-hooks-dir HOOKSPATH]
[--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
[--key KEY] [-d {all,imports,bootloader,noarchive}] [-s]
[--noupx] [--upx-exclude FILE] [-c] [-w]
[-i <FILE.ico or FILE.exe,ID or FILE.icns>]
[--version-file FILE] [-m <FILE or XML>] [-r RESOURCE]
[--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
[--win-no-prefer-redirects]
[--osx-bundle-identifier BUNDLE_IDENTIFIER]
[--runtime-tmpdir PATH] [--bootloader-ignore-signals]
[--distpath DIR] [--workpath WORKPATH] [-y]
[--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
scriptname [scriptname ...]
从pyinstaller的帮助中可以看到,如果给打包后的exe程序添加版本信息可以使用
pyinstaller [--version-file FILE]
打包并添加版本信息
pyinstaller.exe -F --version-file file_version_info.txt test.py
这时候有人会有疑问了,file_version_info.txt
,这个文件里都有什么内容呢?我如何获取这个文件呢?
-
使用命令行
这时候你可以找一个有版本信息的exe文件,然后执行以下命令,就可以获得file_version_info.txt
这个文件了,然后根据需要修改里面的内容,pyi-grab_version.exe
这个命令是安装了pyinstaller
之后才会有的pyi-grab_version.exe .\test.exe 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=(1, 0, 0, 0), prodvers=(1, 0, 0, 0), # 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=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 fileType subtype=0x0, # Creation date and time stamp. date=(0, 0) ), kids=[ StringFileInfo( [ StringTable( u'000004b0', [StringStruct(u'Comments', u''), StringStruct(u'CompanyName', u'test'), StringStruct(u'FileDescription', u'test'), StringStruct(u'FileVersion', u'1.0.0.0'), StringStruct(u'InternalName', u'test'), StringStruct(u'LegalCopyright', u''), StringStruct(u'LegalTrademarks', u''), StringStruct(u'OriginalFilename', u'test.exe'), StringStruct(u'ProductName', u'test'), StringStruct(u'ProductVersion', u'1.0.0.0'), StringStruct(u'Assembly Version', u'1.0.0.0')]) ]), VarFileInfo([VarStruct(u'Translation', [0, 1200])]) ] )