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

分类: 计算机技术
推荐阅读:
#![allow(unused)] 的作用 #![allow(unused)] 是 Rust 编程语言中的一个指令。这个特定的指令用于消除编译器关于未使用代码或变量的警告。
Python min()函数 min() 是 Python 的内置函数之一,用于返回给定可迭代对象中的最小值。该函数可以接受多个参数,也可以接受一个可迭代对象作为参数。
Python计算卡特兰数(catanlan number) 卡特兰数(Catalan number),是组合数学中一种常出现于各种计数问题中的数列;本文使用Python来计算卡特兰数;
Python生成n个元素的全排列 本文将使用Python语言编写程序生成n个元素的全排列,代码不使用第三方库;
Python内置函数大全 该文档详细讲解了几乎所有的Python内置函数,并提供了相关示例;
Python实现与智能机器人交互 本文将利用API与智能机器人进行人机交互,进行简单的聊天对话;代码由Python语言实现。