PyInstaller设置过程说明

问题描述 投票:1回答:1

是否有一种方法可以使用给定的过程描述来编译Python脚本?例如,我有一个名为“ main.py”的文件,编译后我有“ main.exe”。当我运行脚本时,它在任务管理器中显示“ main”,但是我想要“ My python script”之类的东西。 PyInstaller可以吗?

python pyinstaller
1个回答
0
投票

当然可以。您需要做的是(请参阅here获取文档):

  1. 获取一个exe文件,该文件包含您想要的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规范文件生成exe,则可以用此步骤4代替。

  1. version='file_version_info.txt'文件中添加main.spec
    exe = EXE(...
              ...
              version='file_version_info.txt'
              )
    并运行pyinstaller main.spec
  2. 示例

在您的情况下,要在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])])
  ]
)

© www.soinside.com 2019 - 2024. All rights reserved.