Understanding the fix for the known bug: cx_Freeze

2019-08-14 07:35发布

问题:

I have been trying to create a standalone GUI app for Mac OSX based on a python 3 script (version 3.7). The .py script works perfectly when launched directly from the terminal. However this is for my father that needs assistance when downloading a .jpg, so he needs a simple double click app.

Unfortunately all the tools I try to use seem to have known bugs with the modules I'm using (py2App = openpyxl / pyinstaller = tkinter). The one I'm trying to use now is cx_Freeze.

However there is again a know bug with Python 3.7 described

  • here
  • and here

I've been trying to fix this on my mac OSX machine but cannot find the file that is being referred to (on this GIT-hub, the code linked by the first post hereabove).

I would like to fix this bug, but I would also like to understand why this is happening to increase my knowledge of both python and creating standalone apps.

Unfortunately, I'm not good enough to understand how to fix it by reading the GIT-hub posts (as they are directed to Windows systems and I do not find the files), nor why this bug occurs.

Thanks in advance for your help.

for info, here is a copy of the terminal output when launching the created executable:

/Users/USER_NAME/Desktop/Python/DAD_PROJECT/build/exe.macosx-10.9-x86_64-3.7/PROJECT_NAME ; exit;
MacBook-Pro-de-USER_NAME:~ USER_NAME$ /Users/USER_NAME/Desktop/Python/DAD_PROJECT/build/exe.macosx-10.9-x86_64-3.7/PROJECT_NAME ; exit;
Fatal Python error: initfsencoding: unable to load the file system codec
ImportError: invalid flags 1545637508 in 'encodings'

Current thread 0x00007fff98191380 (most recent call first):
Abort trap: 6
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Opération terminée]

EDIT and for good measure, my setup.py file as well:

Please note that this was automatically generated on my Mac using cxfreeze-quickstart as advised on cx-freeze.readthedocs

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('PROJECT_NAME.py', base=base, targetName = 'PROJECT_NAME')
]

setup(name='PROJECT_NAME',
      version = 'DAD_PROJECT',
      description = 'Project for my dad',
      options = dict(build_exe = buildOptions),
      executables = executables)

回答1:

To find the path to the freezer.py file you need to modify, run the following in a Python console:

from cx_Freeze import freezer
print(freezer.__file__)

Modify then this file according to this commit of the cx_Freeze repository, which means remove the red lines annotated with - and add the green lines annotated with +.