开始之前,先介绍.spec文件。
.spec文件在执行打包命令后会自动创建。在执行命令的当前目录下应该就可以直接看到。
以labelme.spec为例,长这个样子:
# -*- mode: python -*- # vim: ft=python import sys sys.setrecursionlimit(5000) # required on Windows a = Analysis( ['labelme/__main__.py'], pathex=['labelme'], binaries=[], datas=[ ('labelme/config/default_config.yaml', 'labelme/config'), ('labelme/icons/*', 'labelme/icons'), ('labelme/translate/*.qm', 'labelme/translate'), ], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], ) pyz = PYZ(a.pure, a.zipped_data) exe = EXE( pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name='labelme', debug=False, strip=False, upx=True, runtime_tmpdir=None, console=False, icon='labelme/icons/icon.ico', version="file_verison_info.txt" ) app = BUNDLE( exe, name='labelme.app', icon='labelme/icons/icon.icns', bundle_identifier=None, info_plist={'NSHighResolutionCapable': 'True'}, )
其中的EXE里有个 _ _version="file_verison_info.txt"__ , 这一句是我自己添加的,本来没有。这一句就是来指定版本信息的。
之后你打包就直接使用 pyinstaller xx.spec,不再用写冗长的命令了。
那 file_verison_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=(4, 5, 9, 4), # 文件版本 prodvers=(4, 5, 9, 4), # 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'040904B0', [StringStruct(u'CompanyName', u'xxx有限公司'), StringStruct(u'FileDescription', u'图像标注工具'), # 文件说明 StringStruct(u'FileVersion', u'4.5.9'), StringStruct(u'InternalName', u'SVN'), StringStruct(u'LegalCopyright', u'xxx有限公司版权所有'), #版权 StringStruct(u'OriginalFilename', u'labelme.exe'), #原始文件名 StringStruct(u'ProductName', u'labelme'), #产品名称 StringStruct(u'ProductVersion', u'4.5.9')]) #产品版本 ]), VarFileInfo([VarStruct(u'Translation', [2052, 1200])]) # 语言 ] )
打包后的exe,在属性里的详细信息,可以看到对应信息。
好吧,本次到此为止。 下次我们说说使用 --add-data 打包额外资源。
源文章:https://blog.csdn.net/u012219045/article/details/113977724?spm=1001.2014.3001.5501