PyInstaller设置进程描述

4

有没有一种方法可以使用给定的进程描述编译Python脚本?例如,我有一个名为'main.py'的文件,编译后我得到了'main.exe'。当我运行我的脚本时,在任务管理器中会显示'main',但我想要像'My python script'这样的东西。使用PyInstaller是否可能实现这个目标?

1个回答

6

当然,这是可能的。你需要做的是(请参阅此处的文档):

  1. 获取一个包含你想要的元数据类别的 exe 文件
  2. 在命令提示符中运行 pyinstaller 工具:pyi-grab_version C:\path\to\that\file.exe
  3. 编辑从步骤2获得的文件 file_version_info.txt
  4. 运行 pyinstaller --version-file=file_version_info.txt main.py

如果你使用 pyinstaller spec file 构建你的 exe,则可以用以下内容替换第4步:

  1. 在你的 main.spec 文件中添加 version='file_version_info.txt'
    exe = EXE(...
              ...
              version='file_version_info.txt'
              )
    

    然后运行 pyinstaller main.spec

示例

在您的情况下,您想要编辑的元数据类别是file_version_info.txt中的FileDescription。以下是一个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, 2, 3, 0),
    prodvers=(1, 2, 3, 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=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'040904b0',
        [StringStruct(u'CompanyName', u'MyCompany'),
        StringStruct(u'FileDescription', u'MyApp'),
        StringStruct(u'FileVersion', u'1.23.0'),
        StringStruct(u'InternalName', u'cardprocess'),
        StringStruct(u'LegalCopyright', u'No Copyright © 2020'),
        StringStruct(u'OriginalFilename', u'myapp.exe'),
        StringStruct(u'ProductName', u'myapp'),
        StringStruct(u'ProductVersion', u'1.23.0')])
      ]), 
    VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
  ]
)


我使用.spec文件来构建我的.exe,我必须说这个解决方案和示例绝对精彩!太棒了,谢谢! - fishbacp

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接