pythontkinterimporterrorcx-freeze

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


I am trying to convert a .py file to .exe using cx_Freeze 5.1.1., but an ImportError: DLL load failed pops up every time I try to run the file. Based on the suggested solutions here and here, I added tcl86t.dll and tk86t.dll to the list of included files. They appear in the build folder, but the error message keeps popping up.

Here is my setup.py:

import sys
import os
from cx_Freeze import setup, Executable

os.environ["TCL_LIBRARY"] = r"C:/Users/Name/AppData/Local/Programs/Python/Python36-32/tcl/tcl8.6"
os.environ["TK_LIBRARY"] = r"C:/Users/Name/AppData/Local/Programs/Python/Python36-32/tcl/tk8.6"


base = "Win32GUI" if sys.platform=="win32" else None


build_exe_options = {"packages": ["winsound", "random", "time", "tkinter", "math"],
"include_files": ['tcl86t.dll',
                 'tk86t.dll']}

setup(
name = "Game",
author = "Name",
description = "game description",
options = {"build_exe": build_exe_options},
executables = [Executable("game.py", base=base)]
)

I'm using Python 3.6.3 and Windows 10. Any help would be greatly appreciated!


Solution

  • In cx_Freeze version 5.1.1, the included modules are in a subdirectory lib of the build directory. The tcl86t.dll and tk86t.dll DLLs apparently need to be moved there as well.

    You can do this with the following modification of your setup.py script:

    build_exe_options = {"packages": ["winsound", "random", "time", "tkinter", "math"],
                         "include_files": [('tcl86t.dll', os.path.join('lib', 'tcl86t.dll')),
                                           ('tk86t.dll', os.path.join('lib', 'tk86t.dll'))]}