使用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

执行完后,我们会在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

最终效果图:

pyi-set_version

原创内容,如需转载,请注明出处;

本文地址: https://www.perfcode.com/p/706.html

分类: 计算机技术
推荐阅读:
QtSpim: Attempt to execute non-instruction at 0x00400030 错误解决方法 使用QtSpim运行MIPS32汇编代码时提示Attempt to execute non-instruction at 0x00400030 错误表示你的程序没有正确退出;
TypeError: __format__ must return a str, not NoneType 在 Python 中,如__format__()方法必须返回一个字符串,否则将触发类似TypeError: __format__ must return a str, not NoneType的错误;
Python实现猜拳小游戏 曾经给一个小屁孩做的作业,放出来分享。。。实现思路: 定义一个玩家类;实现获取用户的输入。 定义一个机器人类;实现机器人的输入。 定义一个裁判类;裁判判断双方胜负。 定义游戏桌面;实现游戏的启动和管理。
Golang中imported and not used:这类错误解决办法 在Golang中,比较容易碰到诸如 imported and not used: "time" 这样的错误;在这里表示你导入了一个time包却没有使用它;
Python里with语句的用法与技巧 本文将详细讲解Python语言中with语句的用法,以及如何让自定义的类也支持with语句;
Python将数转换为带有千位分隔符的形式 在这篇文章中,我们使用Python将一个数转换为带有千位分隔符的形式;