用cx_freeze编译python3和pyqt4的问题

aqu*_*tae 3 python windows pyqt4 cx-freeze python-3.x

我正在尝试使用cx_Freeze编译一个我使用Python3和PyQt4编写的简单脚本,但我有三个问题,我无法弄清楚.

  1. 我无法显示图标.我正在使用一个已编译的资源文件,即导入包含资源的.py,我试图按照这里的建议,将imageformats文件夹复制到我的项目文件夹,但似乎没有任何工作.

  2. 我没有使用包含tcl和ttk的severl 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}
)
Run Code Online (Sandbox Code Playgroud)

aqu*_*tae 6

解决了.除了托马斯的指针,我还需要'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}
)
Run Code Online (Sandbox Code Playgroud)