tkinter program compiles with cx_Freeze but program will not launch

后端 未结 3 1164
[愿得一人]
[愿得一人] 2020-11-29 12:23

I\'m trying to create an executable following this tutorial

https://github.com/anthony-tuininga/cx_Freeze/tree/master/cx_Freeze/samples/Tkinter

After some t

相关标签:
3条回答
  • 2020-11-29 13:12

    After trying an even simpler hello world example writing to the console (which also failed) I stumbled across the culprit.

    What could be the reason for fatal python error:initfsencoding:unable to load the file system codec?

    After updating my freezer.py file with the code found here and using the setup.py provided by jpeg, my example app worked. Thank you both for your swift response.

    0 讨论(0)
  • 2020-11-29 13:16

    I have a working setup.py here. Maybe you can try and see if it works after using the same config. Basically sometimes after compiling, the tk and tcl dll/packages are missing and so you need to include them during the setup.

    import sys, os
    from cx_Freeze import setup, Executable
    
    includes = []
    
    include_files = [r"C:\Users\user\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll",
                     r"C:\Users\user\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll"]
    
    base = 'Win32GUI' if sys.platform == 'win32' else None
    
    os.environ['TCL_LIBRARY'] = r'C:\Users\user\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
    os.environ['TK_LIBRARY'] = r'C:\Users\user\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
    
    setup(name="simple_Tkinter",
          version="0.1",
          options={"build_exe":{"includes":[],"include_files":include_files}},
          description="Sample cx_Freeze Tkinter script",
          executables=[Executable("SimpleTkApp.py",base=base)])
    
    0 讨论(0)
  • 2020-11-29 13:27

    Try to modify you setup.py as follows:

    import sys
    from cx_Freeze import setup, Executable
    
    import os
    PYTHON_INSTALL_DIR = os.path.dirname(sys.executable)
    os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
    os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
    
    include_files = [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')),
                     (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll'))]
    
    base = None
    if sys.platform == 'win32':
        base = 'Win32GUI'
    
    executables = [Executable('SimpleTkApp.py', base=base)]
    
    setup(name='simple_Tkinter',
          version='0.1',
          description='Sample cx_Freeze Tkinter script',
          options={'build_exe': {'include_files': include_files}},
          executables=executables)
    

    This should work for cx_Freeze version 5.1.1 (the current version). In this version, the included modules are in a subdirectory lib of the build directory. If you use 5.0.1 or an earlier version, set

    include_files = [os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
                     os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')]
    

    instead.

    See also Getting "ImportError: DLL load failed: The specified module could not be found" when using cx_Freeze even with tcl86t.dll and tk86t.dll added in and python tkinter exe built with cx_Freeze for windows won't show GUI

    EDIT:

    A further problem is that cx_Freeze has a bug with python 3.7 which is not yet corrected. See Cx_freeze crashing Python3.7.0 . You can find there a link to a bug fix which you should apply manually (according to the OP this solved the problem, see comments).

    0 讨论(0)
提交回复
热议问题