我正在尝试使用 cx_Freeze 编译我使用 Python3 和 PyQt4 编写的简单脚本,但我遇到了三个我无法解决的问题。

  1. 我无法让图标出现。我正在使用编译后的资源文件,即导入包含资源的 .py,我尝试遵循建议 这里, ,将 imageformats 文件夹复制到我的项目文件夹,但似乎没有任何效果。

  2. 我没有使用包括 tcl 和 ttk 在内的几个 python 模块,所以我将它们添加到 excludes 选项。然而,它们似乎仍然被添加。

  3. 当我尝试编译时 base='Win32GUI' 运行创建的 exe 会引发异常: 'NoneType' has no attribute 'encoding'

我很确定我的安装脚本有问题,因为 cx_Freeze 文档不是很详细,所以希望有人能指出问题。这是设置脚本。我不会发布我正在编译的脚本,因为它很长,但如果需要,我会尝试创建一个简洁的版本进行测试。

from cx_Freeze import setup, Executable

exe = Executable(
    script='cconvert.py',
    base='Win32GUI'
)

options = dict(
    excludes=['curses', 'email', 'tcl', 'ttk']
)

setup(
    name="Coord Convertor",
    version="0.1",
    description="A Coordinate converter from DMS to DD",
    requires=['pyqt4 (>=4.8)', 'dtlibs (>=0.4.1)'],
    data_files=['imageformats'],
    executables=[exe],
    options={'build-exe': options}
)
有帮助吗?

解决方案

(请注意1。)

2:在 options={'build-exe'... 中,我认为它需要是 build_exe (下划线而不是破折号)。

3:您是否正在尝试访问类似的东西 sys.stdout.encoding 任何地方? sys.stdout 当您使用 Win32GUI 基础时将为 None。甚至一个 print() 调用可能会触发该操作。

其他提示

解决了。除了托马斯的指针之外,我还需要将“imageformats”放在选项中的“include-files”下,而不是“data_files”下。我的最终脚本如下所示:

from cx_Freeze import setup, Executable

exe = Executable(
    script='cconvert.pyw',
    base='Win32GUI'
)

options = dict(
    excludes=['curses', 'email', 'tcl', 'ttk', 'tkinter'],
    include_files=['imageformats']
)

setup(
    name="Coord Convertor",
    version="0.1",
    description="A Coordinate converter from DMS to DD",
    requires=['pyqt4 (>=4.8)', 'dtlibs (>=0.4.1)'],
    executables=[exe],
    options={'build_exe': options}
)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top