Question

I am trying to compile a simple script I wrote using Python3 and PyQt4 using cx_Freeze, but I've got three problems that I just can't figure out.

  1. I cannot get the icons to appear. I am using a compiled resource file for it, i.e. importing a .py containing the resources, and I have tried to follow the advice here, copying the imageformats folder to my project folder but nothing seems to work.

  2. I am not using severl python modules including tcl and ttk so I added them to the excludes option. However, they still seem to be added.

  3. When I try to compile with base='Win32GUI' running the created exe raises an exception: 'NoneType' has no attribute 'encoding'

I'm pretty sure that there is just something wrong with my setup script since the cx_Freeze documentation is not very verbose, so hopefully someone can point out the problem. Here is the setup script. I'm not going to post the script I'm compiling because its quite long, but if its needed I'll try to create a concise version for testing.

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}
)
Was it helpful?

Solution

(Note sure about 1.)

2: In options={'build-exe'..., I think it needs to be build_exe (underscore instead of dash).

3: Are you trying to access something like sys.stdout.encoding anywhere? sys.stdout will be None when you use the Win32GUI base. Even a print() call might trigger that.

OTHER TIPS

Solved. In addition to Thomas' pointers, I needed 'imageformats' to be under 'include-files' in the options, not 'data_files'. My final script looks like this:

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}
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top