pyinstaller常用參數

參數 說明
-w 不顯示控制台
-D 單一目錄
-F 單一檔案。但啟動速度超級慢(約5秒)。有查到補上 –noupx會正常,實測後仍要5秒多才能正常啟動。目前似乎是無解…可惜啊><
–icon=圖路徑 設定圖示
–version-file=file_version_info.txt 執行檔右鍵詳細資料的明細內容

組合以後指令

pyinstaller -w -D --icon=icon.ico --version-file=file_version_info.txt main.py

其中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, 5, 0, 0),
    prodvers=(1, 5, 0, 0),
    # Contains a bitmask that specifies the valid bits 'flags'r
    mask=0x0,
    # 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'000004e6',
        [StringStruct(u'Comments', u'Comments'),
        StringStruct(u'CompanyName', u'CompanyName'),
        StringStruct(u'FileDescription', u'FileDescription'),
        StringStruct(u'FileVersion', u'1.5'),
        StringStruct(u'InternalName', u'InternalName'),
        StringStruct(u'LegalCopyright', u'LegalCopyright'),
        StringStruct(u'OriginalFilename', u'OriginalFilename'),
        StringStruct(u'ProductName', u'ProductName'),
        StringStruct(u'ProductVersion', u'1.5')])
      ]), 
    VarFileInfo([VarStruct(u'Translation', [0, 1254])])
  ]
)

可以由pyinstaller提供的grab_version.py取得
上述內容使用之版本:Python 3.6.5pyinstaller 3.3.1,為截至po文時的最新版本

若之後版本更新不能使用的話

  1. 打開CMD,CD到Python安裝目錄下cd Lib/site-packages/PyInstaller-3.3.1-py3.6.egg/PyInstaller/utils/cliutils/
  2. 輸入python grab_version.py {拖曳任一安裝或免安裝的exe檔到CMD}
  3. 按下ENTER,會自動產生file_version_info.txt ,再將內容修改成自己要的資訊就可以使用了!