使用 cx_freeze 和 bdist_msi 为 PySide 应用程序创建 MSI

Posted

技术标签:

【中文标题】使用 cx_freeze 和 bdist_msi 为 PySide 应用程序创建 MSI【英文标题】:Creating MSI with cx_freeze and bdist_msi for PySide app 【发布时间】:2013-06-25 21:31:52 【问题描述】:

我有一个 PySide 应用程序,我正在尝试使用 cx_freeze 将其打包到 MSI 中。我可以成功创建一个 MSI 安装程序,但是我无法弄清楚如何列出要包含在包中的其他模块。这是我的setup.py 脚本:

import sys
from cx_Freeze import setup, Executable

company_name = 'My Company Name'
product_name = 'My Gui'

bdist_msi_options = 
    'upgrade_code': '66620F3A-DC3A-11E2-B341-002219E9B01E',
    'add_to_path': False,
    'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (company_name, product_name),
    # 'includes': ['atexit', 'PySide.QtNetwork'], # <-- this causes error
    

# GUI applications require a different base on Windows
base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

exe = Executable(script='MyGui.py',
                 base=base,
                 icon='MyGui.ico',
                )

setup(name=product_name,
      version='1.0.0',
      description='blah',
      executables=[exe],
      options='bdist_msi': bdist_msi_options)

我可以使用命令成功创建 MSI

python setup.py bdist_msi

但是根据 documentation 用于打包 PySide 应用程序,我需要包含模块 atexitPySide.QtNetwork。我尝试通过将'includes' 键添加到bdist_msi_options 来做到这一点,但取消注释该行会导致以下错误:

running bdist_msi
error: error in setup script: command 'bdist_msi' has no such option 'includes'

如何让这些模块与生成的可执行文件一起包含在内?

【问题讨论】:

【参考方案1】:

我在 cx-freeze 邮件列表上发布了同样的问题,并收到了an answer。

'includes''packages' 选项用于 'build_exe' 命令,因此对 setup 的调用需要包含这两个命令。

bdist_msi_options = 
    'upgrade_code': '66620F3A-DC3A-11E2-B341-002219E9B01E',
    'add_to_path': False,
    'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (company_name, product_name),
    

build_exe_options = 
    'includes': ['atexit', 'PySide.QtNetwork'],
    

...

setup(name=product_name,
      version='1.0.0',
      description='blah',
      executables=[exe],
      options=
          'bdist_msi': bdist_msi_options,
          'build_exe': build_exe_options)

【讨论】:

以上是关于使用 cx_freeze 和 bdist_msi 为 PySide 应用程序创建 MSI的主要内容,如果未能解决你的问题,请参考以下文章

卸载以前通过 cx_freeze bdist_msi 创建的已安装 msi

cx_冻结。安装后如何安装服务和执行脚本

python3生成标签云

cx_Freeze 不工作 - 没有名为 cx_Freeze 的模块

Python,AttributeError:模块'google.cloud.bigquery'在cx_Freeze构建后没有属性'Client'

使用java加密和解密密码使用啥API和算法