balian

真的很抱歉现在才贴出这篇博文。

安装PyInstaller2步骤请见:
使用PyInstaller2将Python脚本转化为可执行文件(上-安装部分)
http://www.cnblogs.com/balian/archive/2012/11/21/2780503.html

一些基本的使用步骤请见:
使用PyInstaller2将Python脚本转化为可执行文件(中-使用部分)
http://www.cnblogs.com/balian/archive/2012/11/22/2782308.html

本文博客园balian原创,欢迎转载,转载请说明原作者。

现在看看怎样给生成的可执行文件自定义图标。

PyInstaller2默认图标如下图所示。

image

如果要更换图标,请先准备好图标文件(文件后缀名为ico)。将需要的图标文件直接拷贝到C:\pyinstaller2文件夹。下图是一个例子。图标文件的文件名是tree.ico。

image

接着在Pyintstller2安装文件夹下运行如下命令,假设示例Python脚本文件main.py在c:\scripts文件夹中:

C:\pyinstaller2>python pyinstaller.py -F --icon=tree.ico c:\scripts\main.py

命令中参数--icon=tree.ico表示导入图标文件tree.ico。

该命令具体执行效果如下图。

image

带有新图标的main.exe文件可以在文件夹C:\pyinstaller2\main\dist找到,如图。

image

那怎样给生成的可执行文件加上版权和版本信息呢。

PyInstaller2可以根据一个文本文件给生成的可执行文件加上版本和版权信息。只要在命令中加入参数--version-file=就可以了,--version-file=version.txt就表示将文件version.txt中的版本版权信息加入到可执行文件。

这里有一个version.txt文件的典型范例。

 
VSVersionInfo(
  ffi=FixedFileInfo(
    filevers=(1, 0, 91, 1),
    prodvers=(1, 0, 92, 1),
    mask=0x3f,
    flags=0x0,
    OS=0x40004,
    fileType=0x1,
    subtype=0x0,
    date=(0, 0)
    ),
  kids=[
    StringFileInfo(
      [
      StringTable(
        \'040904B0\',
        [StringStruct(\'CompanyName\', \'www.cnblogs.com/balian\'),
        StringStruct(\'FileDescription\', \'An PyInstaller Sample App\'),
        StringStruct(\'FileVersion\', \'1.0.93.1\'),
        StringStruct(\'InternalName\', \'mainX\'),
        StringStruct(\'LegalCopyright\', \'www.cnblogs.com/balian. All rights reserved.\'),
        StringStruct(\'OriginalFilename\', \'AmAin.eXE\'),
        StringStruct(\'ProductName\', \'Running on MS Windows\'),
        StringStruct(\'ProductVersion\', \'1.0.94.1\')])
      ]),
    VarFileInfo([VarStruct(\'Translation\', [1033, 1200])])
  ]
)

 

如果想知道这个文件怎么来的,请看这篇博文:

PyInstaller2的信息文件Version的生成
http://www.cnblogs.com/balian/archive/2013/02/18/2915105.html

将version.txt文件根据需要修改以后,拷贝到到C:\pyinstaller2文件夹,执行下面的命令即可。

C:\pyinstaller2>python pyinstaller.py -F --icon=tree.ico --version-file=version.txt c:\scripts\main.py
命令执行如下图:
image

请看下面两个图中生成文件的版本版权信息和version.txt中对应信息的位置比对。显然这样就知道怎么修改version.txt文件了。

Version_Info_temp_2

image

请注意信息字段StringStruct(\'InternalName\', \'mainX\'),如果将生成的可执行文件拷贝到Win XP,在文件属性中,就很容易能找到它。

image


如果项目没那么复杂,一般情况下,可以考虑将filevers,prodvers,\'ProductVersion\'和\'FileVersion\'设置成一致的值。比如:

......
filevers=(1, 0, 2, 1),
prodvers=(1, 0, 2, 1),
......
StringStruct(\'FileVersion\', \'1.0.2.1\'),
......
StringStruct(\'ProductVersion\', \'1.0.2.1\')])
......


请试试看这是一个什么效果。

分类:

技术点:

相关文章:

  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2021-09-23
  • 2021-09-19
  • 2022-03-05
猜你喜欢
  • 2022-02-28
  • 2021-11-13
  • 2022-12-23
  • 2021-05-27
  • 2022-01-10
  • 2022-01-10
  • 2022-12-23
相关资源
相似解决方案