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

分类: 计算机技术
推荐阅读:
PySide6 事件详细教程 在PySide6中,事件是GUI应用程序中用户交互和其它系统事件的基本构成块;PySide6中的事件允许您捕获和处理各种类型的事件,从而实现对用户界面的交互和响应;
Rust:if this is intentional, prefix it with an underscore解决方法 编译Rust程序时提示:if this is intentional, prefix it with an underscore: `_x`,这表明存在一个未使用的变量 x,你可以将其删除或在变量名前添加一个下划线前缀;
Rust获取操作系统类型 在Rust编程语言中,你可以使用标准库中的std::env模块来获取操作系统类型。具体来说,你可以使用std::env::consts::OS来获取操作系统类型的字符串表示。
Python compile()函数 在 Python 中,compile() 是一个内置函数,用于将字符串或AST对象编译成字节码或代码对象。编译后的字节码或代码对象可以在多个 Python 解释器中执行,从而避免每次执行时重新编译代码。
Go语言的多返回值 Go语言革命性地在静态开发语言阵营中率先提供了多返回值功能。这个特性让开发者可以从原来用各种比较别扭的方式返回多个值的痛苦中解脱出来,既不用再区分参数列表中哪几个用于输入,哪几个用于输出,也不用再只为了返回多个值而专门定义一个数据结构。
rand()和srand()函数在C语言中的应用 本文通过示例介绍rand()函数和srand()函数在C语言中的用法;