使用 cx_Freeze 创建 .msi 安装程序 -- 安装时显示消息

Using cx_Freeze to create .msi installer -- display message upon install

我正在使用 cx_Freeze 将 python 脚本编译成 .msi 安装文件。阅读 this very helpful thread 后,我已经能够在安装过程中生成编译后的 exe 程序的快捷方式。此外,我想在安装过程中向用户显示某种消息。是否可以相应地配置 cx_Freeze ?如果没有,还能怎么办?

我的代码的相关(简化)位是:

from cx_Freeze import setup, Executable

options = {'optimize': 2}
executables = [Executable('program.py', base='Win32GUI', targetName='program.exe',
                          shortcutName='program', shortcutDir='ProgramMenuFolder')]
  
setup(name='program', options=options, executables=executables)

命令

python path_to_setup_script.py bdist_msi

用于让 cx_Freeze 创建 .msi 安装程序可以使用 setup() 调用中相应的 bdist_msi 选项进行自定义:

setup(..., options={..., 'bdist_msi': bdist_msi_options, ...}, ...)

参见corresponding section of the cx_Freeze documentation for a list of the available options with an example, and also

特别是,data 选项可用于向 MSI installer database tables. For example, a Shortcut table can be added to let the installer create a desktop shortcut as described in the thread you've already linked, Use cx-freeze to create an msi that adds a shortcut to the desktop, or a program menu shortcut as described here. Further examples are sketched 添加新数据。

但是,如果您需要修改已在 cx_Freeze code, which is probably the case if you want to modify the text of existing dialogs, you'll probably need to overload this code. In this case, it is probably easier to let cx_Freeze create an executable only (build command) and to use an additional tool, such as for example the script-based tool NSIS (Nullsoft Scriptable Install System) 中定义的表,以便之后生成更可自定义的安装程序。