pyinstaller打包python程序并添加版本信息

安装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])])
      ]
    )
    

Python argparse添加-v参数显示版本号

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值